I’m trying to assign id name attribute to the element via for loop, I can actually do that no problem, but i want to accomplished of putting same Id’s number in every…let’s say 5 element.
Example:
<div id="1"></div>
<div id="1"></div>
<div id="2"></div>
<div id="2"></div>
<div id="3"></div>
<div id="3"></div>
<div id="4"></div>
I’ve tried jquery slice() function, multiple filter selectors and I just can’t figure it out. Please point me to the right direction. Every answer so much appreciated .
As absolutely terrible an idea as this is it can be accomplished via jQuery.
However, I am assuming you’re doing this to style elements, and this is one place newcomers get screwed up is not understanding that ID’s are UNIQUE elements, their only real purpose to be honest is to allow you to uniquely select them. To style things similarly on the same page you want to use classes, not ID’s. In that case selecting and changing every 5th element to the same CLASS is perfectly valid and a normal thing to do.