开发者

Use the same jquery object in a call

Not sure quite how to describe this but this is what i want to achieve:

$('.class').append($(this).attr("unit"));

but this doesn't a开发者_如何学Cppend anything, i don't believe that $(this) is the element.

Im not sure how to do this, but if there is a better way like attaching code to an event on a div, but i can't think of any triggers that work on load.


You need to use .each() here to loop though and have this be what you want, like this:

$('.class').each(function() {
  $(this).append($(this).attr("unit"));
});

Inside the .each() callback closure, this refers to the current class="class" element you're on, and runs for each match.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜