Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery...hide dropdown if click elsewhere except a specific div
    primarykey
    data
    text
    <p>I have a dropdown, which will be closed by calling blur(). It should be closed if you click somewhere else than the dropdown.</p> <p>Now i want to add a function, so if you click somewhere else, the dropdown is still going to be closed UNLESS you click the div called <code>&lt;div class="changeask"&gt;&lt;/div&gt;</code></p> <pre><code>$(document).ready(function () { $(document).delegate("*", "mousedown touchend", function (e) { var target = $(e.target).closest("div.select2-container").get(0), attr; if (target) { $(document).find("div.select2-container-active").each(function () { if (this !== target ) $(this).data("select2").blur(); }); } else { target = $(e.target).closest("div.select2-drop").get(0); var changeask = $("div.changeask"); $(document).find("div.select2-drop-active").each(function () { if (this !== target &amp;&amp; this !== changeask) $(this).data("select2").blur(); }); } </code></pre> <p>Here is the code I have now... I tried lots of ways but it still close once i click somewhere else than the dropdown.</p> <p>Any ideas?</p> <p>I tried to revise the code like this :</p> <pre><code>$(document).ready(function () { $(document).delegate("*", "mousedown touchend", function (e) { var target = $(e.target).closest("div.select2-container").get(0), attr; var changeask = $(e.target).closest('.changeask').length != 0; if (target) { $(document).find("div.select2-container-active").each(function () { if (this !== target &amp;&amp; this!== changeask ) $(this).data("select2").blur(); }); } else { target = $(e.target).closest("div.select2-drop").get(0); $(document).find("div.select2-drop-active").each(function () { if (this !== target &amp;&amp; this!== changeask) $(this).data("select2").blur(); }); } </code></pre> <p>But still not works... Thanks for the help..I really appreciate it</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.
    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