<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
replace
$('.moreButton').parent().animate({ width: '98%' }, 800);
with
$(this).parent().animate({ width: '98%' }, 800);
$('.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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.