1

I am currently using this code:

<script type="text/javascript">
    $(document).ready(function() {

        jQuery("#navmain li").click(function(){
            jQuery(this).toggleClass("selected");
        });

    });
</script>

It works fine BUT it's not working for class .first ... so when I select any other list item it's working but on the first list item I've assigned a class called .first I need so selected to work on that too.

I need to modify the above so that it also works with:

#navmain li.first

UPDATE:

This is the code I need to modify:

Home

I need to catch the SELECTED and add some style to it.

5
  • 1
    Are you sure this is the source of your problem? Your current code should work with the li.first as well. Commented Sep 13, 2011 at 8:02
  • 1
    what is your css for the selected class? I suspect that the styles which you have for .first are overriding the .selected so you will need to update the css. Commented Sep 13, 2011 at 8:03
  • Just wondering, why are you using jQuery instead of $ inside the document ready but using $ outside? Commented Sep 13, 2011 at 8:06
  • 1
    I got this to work fine. Having extra classes on any of the li elements shouldn't make any difference, unless the 'first' style and the 'selected' style clash. Commented Sep 13, 2011 at 8:07
  • If the first class isn't really needed, you can consider removing it and using $("li:first") selector for it Commented Sep 13, 2011 at 8:07

2 Answers 2

1

See this live example.

It works fine for me: http://jsfiddle.net/nQdcR/

Sign up to request clarification or add additional context in comments.

Comments

0

I think it's must works. My example: http://jsfiddle.net/f5JPy/2/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.