开发者

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++});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜