Reputation: 5568
I need to find a div in my HTML called .detailsBox
with jQuery. The div, which is one of a series of divs all with the same class name output in a loop, is going to be slid down when a link is clicked.
Here is the HTML:
<div id="support">
<h2><a href="#" class="title"><?php echo $growing->title; ?></a></h2> <!-- Click on this link... -->
<div class="detailsBox"> <-- ... and this div will slide down from being hidden -->
<div id="tabs-text">
<p class="description"><?php echo $growing->description; ?></p>
</div>
<div id="learnmore">
<a class="sendEmail" target="_blank" id="<?php echo $growing->link;?>" href="<?php echo base_url() . 'channel-partners/tools/' . $growing->link; ?>"><?php echo $growing->link_text; ?></a>
<a class="sendEmail" id="<?php echo $growing->link2;?>" href="<?php echo $growing->link2; ?>"><?php echo $growing->link_text2; ?></a>
</div>
</div>
</div>
I can find the parent div like this:
var parent = $(this).parent().parent();
But I need a way to then find the child .detailsBox
. How do I do that. I tried this and it didn't work:
$(parent + '> div.detailsBox').slideDown();
The console complains that this is an unrecognized expression because I am trying to combine an object and a string. How do I make the whole thing a selector wrapped in jQuery?
Upvotes: 0
Views: 155
Reputation: 66103
Simply use parent.find(".detailsBox")
. However I always recommend prefixing jquery objects with the $ sign, i.e. var $parent = $(...)
Upvotes: 0
Reputation: 20993
you can pass parent as the context parameter in jquery, ie.
$('div.detailsBox', $(parent)).slideDown();
Upvotes: 0
Reputation: 2027
Try parent.children('.detailsBox').slideDown();
The parent()
returns a jQuery object so you have the methods off that object.
Upvotes: 1