focus - Jquery selecting multiple events -


$('.searchbox').blur(function() {    $("#gohan").hide(); }); $('.dropdown').blur(function() {    $("#gohan").hide(); }); 

hi, have searchbox when type in letters, dropdown (id=gohan) consisting of ul numerous li "search results" appears. want dropdown disappear whenever focus on dropdown or searchbox gone, ie click on that's not in searchbox/ul/li. 2 event handlers work fine separately, don't know how make them work together. tried string them like

$('.dropdown, .searchbox').blur(function() { 

but resulted in catastrophic failure. idea on condition/selector fix this? i've try encapsulate both dropdown , searchbox 1 div containing them , selecting big container, didn't work either. if searchbox isn't out of focus, there must check see if dropdown isn't out of focus too. then, if both aren't in focus, hiding. right logic?

it easier hide #gohan if watched document.body clicks , focus , inspected target of fired event. if user clicks or focuses on not within 'widget' or set of 'widget elements' hide controls , let user continue doing doing.

var handler = function(e){     var ismywidget = $(e.target).hasclass('searchbox') || $(e.target).hasclass('dropdown');     if(!ismywidget ){         $('#gohan').hide();     } }   $(document.body).click(handler).focus(handler); 

depending on dom , elements watching, might able check ancestors of searchbox/dropdown , check see if target element has specific ancestor.

example:

var ismywidget = $(e.target).closest('.widgetcontainer').length > 0; 

this make if widget evolves contain other controls, using new controls not hide widget (as long within same ancestor, i.e. parent div).


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -