I have a jquery script where if user mouseenter, element is .show(), and mouseleave, element is .hide(). But what if you have the user click, and want to show the element even if the mouse leaves? How would you override the mouseleave, when user clicks?
My script goes something like this
$('.block').live("mouseenter",function(){
var id= $(this).attr('id');
$('#'+id).show();
$(this).click(function(){
//show? is this how it works? not sure where click should go.
});
}).live("mouseleave",function(){
var id= $(this).attr('id');
$('#'+id).hide();
});
How do I deal with click?
Thanks!
You can unbind the mouseleave event handler when the user clicks the div
Try could even try using using
$('.block').hover(function(){},function(){})instead of handling themouseoverandmouseleaveevents individually.Also if possible use delegation instead of usinglive. But that is just an opinion not related to your question.Edit : with delegate . Note for this to work the div.blocks need to be as
Also you would need to remove the class block from the div which is clicked so as to counter the effect of
.liveor.delegate