Tony
Tony

Reputation: 12695

jQuery How to remove class for each element?

I'm wondering how to remove the selected class of the all a element of the list ? I tried

$("#navigation li a").removeClass("selected");

but it seems not to be working.

        $('#navigation li').hover(function () {
            $(this).css('cursor', 'pointer');
        }, function () {
            $(this).css('cursor', 'auto');
        });

        <ul id="navigation">
            <li class="home"><a class="selected"></a></li>
            <li class="about"><a>text1</a></li>
            <li class="services"><a>text2</a></li>
            <li class="portfolio"><a>text3</a></li>
            <li class="contact"><a>text4</a></li>
        </ul>

Upvotes: 1

Views: 5723

Answers (3)

Pehmolelu
Pehmolelu

Reputation: 3564

It seems to be working: http://jsfiddle.net/eG8ZS/

Maybe another part of script is not working?

Upvotes: 0

Jamiec
Jamiec

Reputation: 136074

Your code is removing the selected class from the li you hover over, rather than the a within.

Upvotes: 0

Kevin Bowersox
Kevin Bowersox

Reputation: 94429

Make sure you have jquery setup correctly your example seems to be working. I setup a fiddle and it works fine: http://jsfiddle.net/kpDTV/

Upvotes: 3

Related Questions