Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery selection of elements with no visible children
    primarykey
    data
    text
    <p>Here's my goal: do something on an element, an <code>&lt;optgrooup&gt;</code>, if all of its children are invisible.</p> <p>My code below outlines the in red if it has <em>any</em> invisible children. But I want to do so only if <em>all</em> the children are invisible. If the element has any children that are visible, then don't highlight it.</p> <p>How can I tweak the jQuery selector to do that?</p> <p>Thanks in advance.</p> <pre><code>&lt;select multiple="multiple" name="availableInstanceId" id="availableInstanceId"&gt; &lt;optgroup label="Option Group 1"&gt; &lt;option &gt;visible item 1&lt;/option&gt; &lt;option &gt;visible item 2&lt;/option&gt; &lt;/optgroup&gt; &lt;optgroup label="Option Group 2 - Should be highlighted"&gt; &lt;option style="display:none;"&gt;invisible A&lt;/option&gt; &lt;option style="display: none"&gt;invisible B&lt;/option&gt; &lt;/optgroup&gt; &lt;optgroup label="Option Group 3 - Should not be highlighted"&gt; &lt;option &gt;visible C&lt;/option&gt; &lt;option style="display: none"&gt;invisible D&lt;/option&gt; &lt;/optgroup&gt;&lt;/select&gt; &lt;script type="text/javascript"&gt; var filterOptions = function(e) { // Goal: highlight the &lt;optgroup&gt;'s that have *only* invisible children $( '#availableInstanceId &gt; * &gt; *:hidden').parent().css("border","3px solid red"); } $(document).ready(function() { filterOptions(); }); &lt;/script&gt; </code></pre> <p>Screenshot of image here: <a href="http://img144.imageshack.us/img144/556/selectexample.gif" rel="noreferrer">http://img144.imageshack.us/img144/556/selectexample.gif</a></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.
 

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