I am trying to use:
$(\'mydiv\').delegate(\'hover\', function() {
$(\'seconddiv\').show();
}, function() {
//For some reason jQuery won\'t ru
With delegate()(docs) , you assign it to a container, and the first argument is the element that should trigger the event.
Also, .delegate()
accepts only one function, so for the hover
event you need to test the event.type
to determine show()(docs) or hide()(docs) .
$('.someContainer').delegate('.someTarget','hover', function( event ) {
if( event.type === 'mouseenter' )
$('seconddiv').show();
else
$('seconddiv').hide();
});
For show/hide, a shorter way to write this is to use toggle()(docs), which can accept a switch argument where true
means show
and false
means hide
:
$('.someContainer').delegate('.someTarget','hover', function( event ) {
$('seconddiv').toggle( event.type === 'mouseenter' );
});
Note that the mouseenter
event is reported as of jQuery 1.4.3
. If you're using 1.4.2
, it will be reported as mouseover
.
EDIT:
If I'm understanding your comments below, you'd have something like this (using the proper selectors of course).
$('mydiv').delegate('seconddiv','hover', function( event ) {
$(this).toggle( event.type === 'mouseenter' );
});