javascript - When to close custom build jQuery dropdown -


i made simple dropdown using <div> (parent), <span> (current selection) , <ul> (options). works fine. want if user clicks anywhere on page, have close, "real" <select> element.

what this:

$(document).delegate('body','click',function(){    if(isexpanded){close();} }); 

and works. worried performance. wise listen click events on document node? there better way?

thank you.

you make use of blur event. while elements don't support default, adding tabindex=... makes them fire blur event: http://jsfiddle.net/ugsta/.

html:

<div tabindex="1">     <ul>         <li>1</li>         <li>2</li>         <li><span>3</span></li>     </ul> </div> 

javascript:

$('div').blur(function(){alert(1)}) 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -