Javascript examples for jQuery Selector:id
Rebuild and set DIV's id
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.js"></script> <script type="text/javascript"> $(window).load(function(){/*from ww w . j av a 2 s .c om*/ $('div[id^="div_"]').each(function(i){ this.id = 'div_'+(++i) }) }); </script> </head> <body> <div id="div_3"> 1 </div> <div id="div_2"> 2 </div> <div id="div_5"> 3 </div> </body> </html>