jQuery: test if element is first of MATCHED elements
<p>I have several divs that are alerts. The user dismisses them and after the final one (which is the FIRST in the DOM) I need to trigger some jquery magic.</p>

<p>Here's some simplified HTML:</p>

<pre><code>​&lt;body&gt;
&lt;div class=""&gt;Bla bla bla&lt;/div&gt;
&lt;div class="alert"&gt;A&lt;/div&gt;
&lt;div class="alert"&gt;B&lt;/div&gt;
&lt;/body&gt;​
</code></pre>

<p>Here's what I'm trying to do with jquery...</p>

<pre><code>$(".alert").click( function() {

if ( $(this).is(".alert:first") ) { 
//do stuff
}

});
</code></pre>

<p>It doesn't work. The conditional never returns true. The only way I can get it to work is using <code>.index()</code> but that sucks because if the order of the markup changes it will break the script.</p>

<p>What am I doing wrong?</p>

<p>EDIT: The solution uses <code>.index()</code> but in a way that I did not realize was possible. It <em>is</em> relative to the matched selection if used in that way. Thanks!</p>
