Reputation: 29
I'm using this code: http://jsfiddle.net/fGHmF/2/
now I want to add the word "size" to every IMG id. for instance:
<img src='images/size1.png' alt='img1' id='size1' />
<img src='images/size2.png' alt='img2' id='size2' />
<img src='images/size3.png' alt='img3' id='size3' />
<img src='images/size4.png' alt='img4' id='size4' />
what do i need to change in the java script?
Upvotes: 1
Views: 63
Reputation: 7562
try below
$('img').each(function(i){
$(this).attr('id', 'size' + $(this).attr('id'));
});
see here
Upvotes: 0
Reputation: 57095
$('img').attr('id', function() {
return 'size'+this.id;
});
Upvotes: 2
Reputation: 11302
$('img').attr('id', function() {
return 'size' + this.id;
});
Upvotes: 6
Reputation: 6025
Try
$('img').each(function(){
$(this).attr('id', 'size' + $(this).attr('id'))
})
Upvotes: 1