jquery select problem

Posted by codedude on Stack Overflow See other posts from Stack Overflow or by codedude
Published on 2010-04-23T23:09:31Z Indexed on 2010/04/23 23:13 UTC
Read the original article Hit count: 231

Filed under:

Say I have an unordered list like so:

<ul>
<li>Some Text</li>
<li>Some Text</li>
<li>Some Text</li>
<li>Some Text</li>
</ul>

I want to use jquery so that when I click a "li", the background changes to blue. So I do this:

    $('li').click(function() {
    $(this).addClass('active');
});

And the "active" class has as background of blue. However, I can't figure out how to make it so that when I click another "li", the other "li" that has a background of blue stops having a background of blue. I guess what I'm trying to say is how to make only one "li" have a background of blue at a time--using jquery.

© Stack Overflow or respective owner

Related posts about jQuery