jQuery - If first element has class then Function <p>I'm looking to add a piece of code sitewide to affect all of my pages.</p> <p>Right now, it goes something like this.</p> <pre><code>if($('#container &gt; div:first').attr('id') == 'filterOptions') { $('#container').prepend('&lt;div class="banner"&gt;&lt;/div&gt;'); } </code></pre> <p><strong>The output:</strong></p> <pre><code>&lt;div id="container"&gt; &lt;div class="banner"&gt;&lt;/div&gt; &lt;div id="filterOptions"&gt;&lt;div&gt; &lt;/div&gt; </code></pre> <p><strong>Example</strong>, if the container looked like this:</p> <pre><code>&lt;div id="container"&gt; &lt;div class="existingBanner"&gt;&lt;/div&gt; &lt;div id="filterOptions"&gt;&lt;div&gt; &lt;/div&gt; </code></pre> <p>Nothing would happen as the first div doesn't have the filterOptions ID.</p> <p>Now I've hit a bump as I also have something that looks like this that the banner DOES get added to</p> <pre><code>&lt;div id="container"&gt; &lt;a class="existingBanner" href="#"&gt;&lt;/a&gt; &lt;div id="filterOptions"&gt;&lt;div&gt; &lt;/div&gt; </code></pre> <p>This will essentially have a double banner which is something I want to avoid. because it's an anchor instead of a div.</p> <p>So my question is. instead of targeting <strong>div:first</strong> how would I target ALL elements?</p> <p><strong>Something like...</strong></p> <p><code>if($('#container &gt;</code> <strong>any</strong><code>:first').attr('id') == 'filterOptions') { ... }</code></p>