Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: On form input focus, show div. hide div on blur (with a caveat)
    primarykey
    data
    text
    <p>I am able to make a hidden div show/hide when an input field is in focus/blur using the following code:</p> <pre><code> $('#example').focus(function() { $('div.example').css('display','block'); }).blur(function() { $('div.example').fadeOut('medium'); }); </code></pre> <p>The problem is I want <code>div.example</code> to continue to be visible when the user is interacting <em>within</em> this div. E.g. click, or highlighting the text etc. within <code>div.example</code>. However <code>div.example</code> fades out whenever the input is not in focus and the mouse is interacting with elements within the div.</p> <p>The html code for the input and div elements is as follows:</p> <pre><code>&lt;p&gt; &lt;label for="example"&gt;Text:&lt;/label&gt; &lt;input id="example" name="example" type="text" maxlength="100" /&gt; &lt;div class="example"&gt;Some text...&lt;br /&gt;&lt;br /&gt;More text...&lt;/div&gt; &lt;/p&gt; </code></pre> <p>How do I make it such that the <code>div.example</code> only disappears when the user clicks outside the input and/or <code>div.example</code>? I tried experimenting with focusin/focusout to check the focus on <code>&lt;p&gt;</code> but that didn't work either.</p> <p>Would it matter that <code>div.example</code> is positioned directly below the input field #example using jQuery? The code that does that is as follows:</p> <pre><code>var fieldExample = $('#example'); $('div.example').css("position","absolute"); $('div.example').css("left", fieldExample.offset().left); $('div.example').css("top", fieldExample.offset().top + fieldExample.outerHeight()); </code></pre> <p>My apologies if this has been asked before, but the many show/hide div questions I read does not cover this. Thanks for your advice. :)</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