Note that there are some explanatory texts on larger screens.

plurals
  1. POchecking all children of a submenu to see if any element has focus in jquery, using :focus selector
    primarykey
    data
    text
    <p>I have a navigation menu which when an item is selected on the menu, a submenu will appear. The submenu can contain 3 possible elements: text to represent a category, a url to take the user somewhere, and a search box with which the user can type data in and hit a button to go to a controller action. For design purposes, every five elements are grouped into one ul.</p> <p>This is an example of such a submenu:</p> <pre><code>&lt;div id = "submenu"&gt; &lt;ul&gt; &lt;li&gt; Products &lt;/li&gt; &lt;li&gt; &lt;a href = "ourproducts"&gt; View Our Products&lt;/a&gt;&lt;/li&gt; &lt;li&gt; &lt;form method="GET" action="/"&gt;&lt;input value="" name="searchproduct"&gt;&lt;input type="Submit" value="Search For Product"&gt; &lt;/form&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I have a mouseleave function on the submenu that will cause the submenu to hide. However, if the form has focus (say the user is trying to type something in and they accidentally bump the mouse), then I do not want the submenu to disappear. </p> <p>This is what I have tried so far:</p> <pre><code>$("#submenu").mouseleave(function () { var childhasfocus= 0; for (var i = 1; i &lt; $(this).children().length; i++) { if ($(this).children[i].is(":focus") == true) { //CODE GOES UP TO HERE BEFORE BREAKING childhasfocus = 1; } } // TRIED THIS- if ($(this + '&gt;:focus').length &gt; 0){ if (childhasfocus != 1){ hideLinks(); } }); </code></pre> <p>Two Questions:</p> <p>1:If one of the elements inside a ul has focus, will the ul also has focus?</p> <p>2:What should I replace my if statement with?</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