Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Using <code>:not</code>, and <code>.not()</code> to select and filter &raquo; <a href="http://jsfiddle.net/bpfU5/1/" rel="nofollow noreferrer">Live Demo</a></h3> <p>The <a href="http://api.jquery.com/not-selector/" rel="nofollow noreferrer"><code>:not(selector)</code></a> does exactly this, and it comes in a couple styles. You can use the <em>selector</em>, or the <em>method</em>. Below is an example of using the selector:</p> <pre><code>$("#container :not(select)"); </code></pre> <p>This will match any child within <code>#container</code> that is <em>not</em> a <code>&lt;select&gt;</code> element. Then we have the method fashion of exclusion, which goes by the same name, but must be ran differently:</p> <pre><code>$("#container").children().not("select"); </code></pre> <p>This runs against the <code>children</code> of the matched elements. In this case, <code>.not</code> acts as a filter. Which brings me to the next example, using <a href="http://api.jquery.com/filter/" rel="nofollow noreferrer"><code>.filter()</code></a> to get the results you want. With this method, we can provide our own custom function to rummage through the results and pick the ones we want:</p> <h3>Using <code>.filter()</code> to filter the matched elements &raquo; <a href="http://jsfiddle.net/bpfU5/" rel="nofollow noreferrer">Live Demo</a></h3> <pre><code>$( "#container" ).children().filter( isNotSELECT ).fadeTo( "slow", .5 );​​​​​​​​​​​​​​​​​​​​​​​​​​​ function isNotSELECT () { // Returns TRUE if element is NOT select return !$(this).is("select"); } </code></pre> <p>In this example, we select all of the children of <code>#container</code>, and then pass them through a filter that we have defined called "isNotSelect". Within our filter, we return either <code>true</code> or <code>false</code> for every element. If we return <code>true</code>, that element will be returned to the result set. If we return <code>false</code>, that element will be removed from the result set. We're asking if the element is <em>not</em> a select. This will return <code>false</code> for all select elements, thus removing them from our collection.</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. 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.
    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