javascript - Why jQuery intermittently fails to detect click? -
why jquery detect click , not?
i have #options
element when clicked #dropdown-menu
shown. when user clicks anywhere outside #dropdown-menu
(except on #options
element) dropdown hidden. here code of time works , doesn't:
jquery( document ).ready( function() { jquery('#options').click( function(){ jquery('#dropdown-menu').slidedown(); }); jquery(document).click( function(event) { if( !jquery(event.target).closest('#dropdown-menu').length && !jquery(event.target).is('#options') ) { if(jquery('#dropdown-menu').is(":visible")) { jquery('#dropdown-menu').hide(); } } }); });
i can't figure out why works intermittently. hard accept code works sometimes. noticed event.target
comes empty string somtimes... bug jquery?
edited:
here fiddle , error can't reproduced.
ok, figured out solution problem. warning: silly , strange!
the problem content of #options
, using icon fontawesome represent 'options' so:
<div id="options"><i class="fa fa-ellipsis-v"></i></div>
i removed <i class="fa fa-ellipsis-v"></i>
content , added using css, works without fail. not sure why does; guess jquery getting confused when clicked on <i>
tag though belogs #options
.
css code add fontawesome icon:
#options:before { content: "\f142"; font-family: fontawesome; }
(thanks everyone's input me pin down problem. appreciate it!)
Comments
Post a Comment