Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can bind the onblur event handler to each of the input elements and check in the handler if any of them have focus (using <a href="https://developer.mozilla.org/En/DOM/Document.activeElement" rel="noreferrer">document.activeElement</a>).</p> <pre><code>&lt;script type="text/javascript"&gt; function checkBlur() { setTimeout(function () { if (document.activeElement != document.getElementById("input1") &amp;&amp; document.activeElement != document.getElementById("input2") &amp;&amp; document.activeElement != document.getElementById("input3")) { alert("I am called"); } }, 10); } &lt;/script&gt; &lt;!-- ... --&gt; &lt;div&gt; &lt;input type="text" id="input1" value="Inside DIV 1" onblur="checkBlur()" /&gt; &lt;input type="text" id="input2" value="Inside DIV 2" onblur="checkBlur()" /&gt; &lt;input type="text" id="input3" value="Inside DIV 3" onblur="checkBlur()" /&gt; &lt;/div&gt; &lt;input type="text" value="Outside DIV" /&gt; </code></pre> <p>Or, instead, using jQuery could simplify the process (especially if you have a lot of inputs):</p> <pre><code>&lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $("#theDiv input").bind("blur", function () { setTimeout(function () { var isOut = true; $("#theDiv input").each(function () { if (this == document.activeElement) isOut = false; }); if (isOut) { // YOUR CODE HERE alert("I am called"); } }, 10); }); }); &lt;/script&gt; &lt;!-- ... --&gt; &lt;div id="theDiv"&gt; &lt;input type="text" value="Inside DIV 1" /&gt; &lt;input type="text" value="Inside DIV 2" /&gt; &lt;input type="text" value="Inside DIV 3" /&gt; &lt;/div&gt; &lt;input type="text" value="Outside DIV" /&gt; </code></pre> <p>EDIT: I wrapped the event handlers inside a <code>setTimeout</code> to make sure that the other element had time to focus.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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