Reputation: 1351
Having problems with a simple jquery mouseover function.
I have a number of dynamically generated icons which when I hover will show a hidden div, and when I mouesout will hide the div.
<div class='lister1'>
<img src='"+path+stat1+"' />
<img src='"+path+stat2+"' />
<img src='"+path+stat3+"' />
<img src='"+path+stat4+"' />
<img src='"+path+stat5+"' />
<img src='"+path+stat6+"' />
</div>
JQuery:
$('.hover_pop').hide();
$(document).on('hover','.lister1 img', function(){
$('.hover_pop').show(), function(){
$('.hover_pop').hide();
}
});
This will show the div but unfortunately will not hide it.
Upvotes: 3
Views: 2691
Reputation: 4688
Try this
$(document).on('hover','.lister1 img', function(){
$('.hover_pop').show()}, function(){
$('.hover_pop').hide();
});
You have closed the curly brace of first function at the end previously
EDITED
$(document).on({
mouseover: function() {
$('.hover_pop').show()
},
mouseout: function() {
$('.hover_pop').hide()
}
}, '.lister1 img');
Upvotes: 1
Reputation: 144709
As of jQuery 1.8 using hover
event with on
method is deprecated, you can code:
$(document).on({
mouseenter: function() {
$('.hover_pop').show()
},
mouseleave: function() {
$('.hover_pop').hide()
}
}, '.lister1 img');
Upvotes: 4