jQuery – Select an element that does NOT have an attribute

Maybe I wasn’t searching in the right way, but I couldn’t find anywhere that would specifically tell me how to select elements that do NOT have an attribute in jQuery. I founds lots of blogs that just repeated the jQuery site on how to find elements that do have an attribute (or one with a specific value) but not the opposite.

So here is the answer

e.g.

<br />
&lt;div id=&quot;parent&quot;&gt;<br />
    &lt;div name=&quot;fred&quot;&gt;&lt;/div&gt;<br />
    &lt;div name=&quot;jane&quot;&gt;&lt;/div&gt;<br />
    &lt;div&gt;pick me!&lt;/div&gt;<br />
    &lt;div name=&quot;rod&quot;&gt;&lt;/div&gt;<br />
&lt;/div&gt;</p>
<p>//the line below will return the div without a name attribute i.e. 'pick <div style="display: none"><a href='http://buyviagraonlineed.org/' title='generic viagra'>generic viagra</a></div> me!'<br />
$(&quot;#parent&quot;).children(&quot;div :not([name])&quot;);</p>
<p>

Obvious I guess, but I couldn’t work this out before staring at the book for ages…. but then if I get no comments I’ll assume it was just me :) )