开发者

foreach jQuery function

开发者 https://www.devze.com 2023-03-31 22:07 出处:网络
I am trying to get a function to work for each .download开发者_StackOverflow社区_now element. I have used the two below with no luck, any idea why?

I am trying to get a function to work for each .download开发者_StackOverflow社区_now element.

I have used the two below with no luck, any idea why?

$(".download_now").each.tooltip({ effect: 'slide'});
$(".download_now").each(tooltip({ effect: 'slide'}));

Neither answer will work, I'm trying it on the following: http://flowplayer.org/tools/demos/tooltip/any-html.html


each() takes a function as an argument. Within that function you can use this to refer to the current element:

$(".download_now").each(function(){
    $(this).tooltip({ effect: 'slide'});
});


You need to wrap the tooltip call inside a function.

each() will then call the function for each iteration, passing the current element as this.

Like so:

$(".download_now").each(function(){
  $(this).tooltip({ effect: 'slide'})
  });


You need to pass a function into the each method. Typically, an anonymous function is used like so:

$('.download_now').each(function() {
    ...
});

Each DOM object can be referenced using this within the function.


You don't need .each(). Just do:

$(".download_now").tooltip({ effect: 'slide'});

(like the first page of the showcase shows)

0

精彩评论

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

关注公众号