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

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -