jquery - Loop through all h2 elements and add unique id -


i need add unique ids h2 tags jquery. dont know how add unique ids of h2 tags same when use attr function , have no idea how change that.

$('h2').attr("id", "rev3"); 

you may use implicit function inside jquerys .each() this

var id = 0; $('h2').each(function(){     $(this).attr("id", "rev" + id);     id++; }) 

.each() loops through result array elements, while this reffers current element.


Comments

Popular posts from this blog

Lists in Python -

android - can not access to progress bar in an other activity -

html - Not able to access next element of an array javascript -