I used this function to animate the parent element of the link:
$(".user-review-toggle").toggle(function(){
$(this).css("backgroundPosition", "0 -12px");
$(this).closest('.user-review').animate({height:150},200);
},function(){
$(this).css("backgroundPosition", "0 0");
$(this).closest('.user-review').animate({height:98},200);
});
But now, what I need to do is to animate the element that sits on top of the link:
<div class="user-contribution">
<p class="user-review"> Review</p> 2. Animate this
<a class="user-review-toggle" href="#">Read more...</a> // 1. Clicking this
There are many .user-contributions divs so the link must only animate the one that is on top of it.
Any suggestions to accomplish this?
You can use
prevto get the immediately-preceding element, e.g.:prevreturns the sibling element immediately before the reference element. In your case, since thepis immediately prior to thea, that’s what you want.