How to see which element was clicked first?
<p>I have a selection menu using <code>toggleClass().</code> to see which menu options were selected:</p>

<pre><code>$('.img1, .img2, .text1, .tex2').click(function() {
    $(this).toggleClass('selected');
});
</code></pre>

<p>The way my selection menu works is that if two elements have the class <code>selected</code> then something will happen. For example:</p>

<pre><code>if ( $('.img1').hasClass('selected') &amp;&amp; ('.text1').hasClass('selected') ) {
    // do something
}
</code></pre>

<p>This all works perfectly however I want to disable the user from picking two <code>imgs</code> or two <code>texts</code>. The way I want to do this is just have the first selected element be removed from the selected class and the second selected element stay selected. For example:</p>

<pre><code>if ( $('.img1').hasClass('selected') &amp;&amp; ('.img2').hasClass('selected') ) {
        // remove selected from the element that was first clicked and keep selected on the element that was clicked second
}
</code></pre>

<p>What would be the best way of achieving this? Thanks in advance.</p>
