I have a css div and within that div another div exists. How can I get the child div while the mouse hovers over the parent div? As here:
<div class="parent">
<div class="child">
</div>
</div>
When the mouse gets over the parent div, I want the child div to be displayed.
children() is an inbuilt method in jQuery which is used to find all the children element related to that selected element. This children() method in jQuery traverse down to a single level of the selected element and return all elements.
grab the second child: $(t). children(). eq(1);
The parent > child selector in jQuery is used to select all elements that are a direct child of the specified element.
This works:
$('.child').hide(); // or $('.parent').children().hide();
$('.parent').hover(
function() { $(this).children('div').show() },
function() { $(this).children('div').hide() }
);
Example at http://jsfiddle.net/4kMuD/, although that uses IDs rather than classes for the selector.
I've assumed (although you didn't say) that you want the child div to disappear again when you're no longer hovering over the parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With