how to add and remove a class from a list of li elements?
<p>if i have an li list like this:</p>

<pre><code>&lt;ul&gt;
&lt;li&gt;first &lt;/li&gt;
&lt;li&gt;second&lt;/li&gt;
&lt;li&gt;third&lt;/li&gt;
&lt;li&gt;fourth&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>How would i write the code in jquery to add a class to the li element , say , first without the class being added to the others?</p>

<p>i tried this but it of course adds to all li elements.</p>

<pre><code>$(document).ready(function() {
$("ul li").click(function() {
if(!$("ul li").hasClass('active'))
{
$("ul li").addClass('active');
}
});

});
</code></pre>

<p>i want to be able to add the class active to only the li element that was click and remove all other exists who have active added to them. how would i do this? thanks</p>
