James Habib
James Habib

Reputation: 11

foreach jQuery function

I am trying to get a function to work for each .download_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

Upvotes: 0

Views: 208

Answers (4)

Felix Kling
Felix Kling

Reputation: 817208

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

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

(like the first page of the showcase shows)

Upvotes: 0

a'r
a'r

Reputation: 37029

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.

Upvotes: 0

Pekka
Pekka

Reputation: 449813

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'})
  });

Upvotes: 0

Paul
Paul

Reputation: 141927

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'});
});

Upvotes: 3

Related Questions