I want to add an identifier to each element of the .content class, and I want each identifier to have an integer increase of 1. Example:
<div class="content" id="content_1"></div> <div class="content" id="content_2"></div>
etc .. I wrote code that looks like this:
var number = 1; $(".content").each(function() { $('.content').attr('id', 'content_' + number); number++; });
This code adds content_2 to both of them, not to content_1 and content_2 , if I have 3 elements with the class .content , they will all have the identifier content_3
Any ideas how I could fix this?
source share