jeudi 3 avril 2014

JQuery Select a Child Element within Previous Closest Element


Vote count:

0




I have some HTML like this:



<article>
<aside>
<p class="target-goal">This is my goal to target, which is initially hidden.</p>
</aside>
<header>
<h1>Title</h1>
<time>5:00</time>
</header>
<a href="somewhere.php" class="toggle">Show Target</a>
</article>


I'm trying to make it so when you click on .toggle I can show p.target-goal.


Here's the jQuery I've been trying, along with several variations using closest, etc.:



$('.toggle').click(function(e) {
e.preventDefault();
$(this).prev('aside').children('.target-goal').slideToggle();
});


Any ideas as to what I might be doing wrong?



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire