Reputation: 4269
I am basically trying to apply slide down navigation in jQuery. I use this code :
<script>
$(document).ready(function() {
$(".menu").hover(function(){
$(".submenu").animate({ height: 'show', opacity: 'show' }, 'slow');
}, function(){
$(".submenu").animate({ height: 'hide', opacity: 'hide' }, 'slow');
});
});
</script>
But when I hover upon a .menu
div then all the .submenu
div gets slide down. So I tried to accomplish it using $(this)
. But I don't know how to do this.
Upvotes: 0
Views: 49
Reputation: 337590
You need to use this
as a context to search for the .submenu
element within, like this:
$(document).ready(function() {
$(".menu").hover(function(){
$(".submenu", this).animate({ height: 'show', opacity: 'show' }, 'slow');
}, function(){
$(".submenu", this).animate({ height: 'hide', opacity: 'hide' }, 'slow');
});
});
Upvotes: 2
Reputation: 2265
Nowadays, you want to bind events like this :
$(document.body).on({
mouseover : function(e) {
$(this).find(".submenu")...
},
mouseout : function (e) {
//...
}
//,...
},".menu");
Upvotes: 0