CSS Power
Pages
Home
Create ID for HTML element using Jquery function
<!DOCTYPE html> <html> <head> <style> div { color:blue; } span { color:red; } b { font-weight:bolder; } </style> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <div>Zero-th <span></span></div> <div>First <span></span></div> <div>Second <span></span></div> <script> $("div").attr("id", function (arr) { return "div-id" + arr; }) .each(function () { $("span",this).html("(ID = '<b>" + this.id + "</b>')"); }); </script> </body> </html> </div>
Here’s a simple Example on how to provide ID's to any Html element using jQuery.. Copy paste the above code to see how it works.
Newer Post
Older Post
Home