I am trying to use:
$(\'mydiv\').delegate(\'hover\', function() {
$(\'seconddiv\').show();
}, function() {
//For some reason jQuery won\'t ru
EDIT: misinformation removed.
If you want to use the hover()
method without delegation, working code would look like this:
$('#mydiv').hover(function() {
$('#seconddiv').show();
}, function() {
$('#seconddiv').hide();
});
Second of all, delegate
is to assign an event handler to a child, so you need to specify a selector first. If you need to make sure this event handler exists for dynamically added elements, I would prefer .live()
in this case with mouseenter
and mouseleave
.
$('#mydiv').live('mouseenter', function() {
$('#seconddiv').show();
}).live('mouseleave', function() {
$('#seconddiv').hide();
});