Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Created August 19, 2010 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmessinger/536797 to your computer and use it in GitHub Desktop.
Save scottmessinger/536797 to your computer and use it in GitHub Desktop.
$('.editable').live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {
function() {
$(this).children('.nubbin_wrapper').show();
}
} else {
function() {
$(this).children('.nubbin_wrapper').hide();
}
}
});
@webandy
Copy link

webandy commented Aug 19, 2010

You should be able to put line 8 in the else condition without wrapping it in a function. Since both code paths are the same, why the event type is mouseover? Is one of those supposed to be show() instead of hide()?

@scottmessinger
Copy link
Author

You're right, it should be show() on line 4.

I'm getting the following error:
Uncaught SyntaxError: Unexpected token ( on line 3.

@scottmessinger
Copy link
Author

I took out the function() on line 4 and 8 and it worked. Thanks!

@jjulian
Copy link

jjulian commented Aug 19, 2010

Yeah no reason to define a fn there. Just do it.

@webandy
Copy link

webandy commented Aug 19, 2010

I had a typo above, I meant why check the event type if both paths are the same. But I see you are trying to toggle a div. You can actually bind "hover" to more than just links with jQuery, and toggle() can replace hide() and show(), this might be a more compact way to accomplish the same:

$('.editable').hover(function() { $(this).children('.nubbin_wrapper').toggle() });

@scottmessinger
Copy link
Author

Originally, I did use hover, but I was reloading a div with ajax and thus needed to use .live(). Live doesn't work with hover--you have to use the two mouse events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment