开发者

Increment value to attr using jquery

开发者 https://www.devze.com 2022-12-22 08:45 出处:网络
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 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

精彩评论

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

关注公众号