Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript detect when drop down list is closed
    primarykey
    data
    text
    <p>Because of the issue explained in this <a href="https://stackoverflow.com/questions/1452387/can-not-use-onmouseover-event-on-select-option-in-ie">question</a> I have a situation where I need to attach the mousewheel event to the drop down list only when it is expanded (I do this in the onclick event). However I need to remove the mousewheel event when the list collapses. How do I go about detecting this?</p> <p>I can't just use the onchange event because the user may not have actually changed their selection. I've tried the onblur event but in most browsers (except IE) the drop list stays focused when the list is collapsed.</p> <p>Cheers.</p> <pre><code>var list = document.getElementById("list"); list.onclick = function (e) { // attach mousewheel list.onmousewheel = function (e) { // ... } // attach click off // This event fires fine in all browsers except FF when the list is expanded. // In firefox it only fires when anywhere in the document is clicked twice. // The first click closes the drop down list as expected and the second one // fires the event. window.document.onclick = function (e) { list.onmousewheel = null; window.document.onclick = null } }; </code></pre> <p><strong>EDIT:</strong> Unfortunately meder's solution doesnt work in firefox. The click event on the document doesn't get fired until i click twice off the drop down list. How do I get around that? It works fine in IE.</p> <p><strong>EDIT2:</strong> I've done some more testing and the following browsers behave as expected</p> <ul> <li>IE 7, </li> <li>Chrome 3</li> <li>Opera 10</li> </ul> <p>Firefox requires 2 clicks in the window to make it work &amp; Safari doesn't work at all.</p> <p>It appears that even when you click off the drop down list firefox maintains focus on it. It's not until the second click occurs that the drop down list eventually loses it's focus.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload