Increment value to attr using jquery
I wan开发者_如何学Pythont to increment the value of i . The "for" loop does not work.
$("a[href$='.xls']").appendTo(".xl1").attr('id','xl'+i);
I search all excel files and places them in a container and increment the value of their id.
Thanks Jean
$("a[href$='.xls']").each(function(i) {
$(this).appendTo(".xl1").attr('id','xl'+i);
})
counting starts from i=0
You can read about function each() here http://api.jquery.com/each/
Using jQuery 1.4.2:
var i=1;
$("a[href$='.xls']")
.appendTo(".xl1")
.attr('id', function(){return 'xl' + i++});
精彩评论