Reputation: 2220
+More
Each block will have an article summary in it.
<div class="contentBlockTwo">
<span class="moreButton">+More</span>
<br /> Or new flashes.</div>
As you can see I have my "spans" as the same class so I can apply the following jQuery to them:
$('.moreButton').click(function () {
$('.moreButton').parent().animate({ width: '98%' }, 800);
});
But no matter which of the "span" items I click, ALL of the "Divs" have the animation applied to them.
How can I apply the animation to the parent of the sender/ clicked "span" without giving each "div" an ID?
Thanks
Upvotes: 2
Views: 1370
Reputation: 4967
replace
$('.moreButton').parent().animate({ width: '98%' }, 800);
with
$(this).parent().animate({ width: '98%' }, 800);
Upvotes: 2
Reputation: 78520
$('.moreButton').click(function () {
$(this).parent().animate({ width: '98%' }, 800);
});
You need to use the this
object otherwise it is re-selecting the parent elements of all .moreButton rather than the one you clicked.
Upvotes: 1