I am trying to iterate over every div with the the id 'slide' and add a number to the end (e.g slide1, slide2, etc)
I have been able to have a series of classes added to each div, but I can only get the same code to rename the first slide, not the rest of them.
$(document).ready(function() {
$("#slide").each(function(i) {
$(this).attr('id', "slide" + (i + 1));
});
});
and jsfiddle here http://jsfiddle.net/YsvCe/1/
Thanks in advance
You should use classes rather than ids for multiple elements.
<div class="slide">hello</div>
...
$(document).ready(function() {
$(".slide").each(function(i) {
$(this).attr('id', "slide" + (i + 1));
});
});
Example: http://jsfiddle.net/QaB76/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With