Jack
Jack

Reputation: 237

animate and Iterate in jQuery

I want to animate the all of the following img:

<img class="image" width="1" src="/assets/vote.gif" alt="option">
<img class="image" width="1" src="/assets/vote.gif" alt="option">
<img class="image" width="1" src="/assets/vote.gif" alt="option">
<img class="image" width="1" src="/assets/vote.gif" alt="option">

i want to set different width of the img use jQuery.animate.

how to?

Upvotes: 0

Views: 53

Answers (2)

Johan
Johan

Reputation: 35213

An extension of the answer above

var width = 100;
$("img").each(function() {
$(this).animate({"width": height+"px"}, 1000);
width += 100;
});

Upvotes: 0

Rost
Rost

Reputation: 3662

You have forgot to wrap this with $():

$("img").each(function() {
    $(this).animate({"width": "100px"}, 1000);
})

And by the way, you can do it much simplier:

$("img").animate({"width": "100px"}, 1000);

Upvotes: 1

Related Questions