1

I have this simple menu with some <ul>s that loads its content onclicking on it. And I want to change the style of every ul on loading the content that belongs to it. Here's the menu: http://jsfiddle.net/EPvGf/11/

2 Answers 2

3

I'd suggest:

$(this).closest('ul').addClass('newStyle');

Though within a click-handler (assuming nested ul elements):

$('li').click(function(e){
    $(e.target).closest('ul').addClass('newStyle');
});

JS Fiddle demo.

References:

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

Comments

1

I think you meant styling the corresponding parent li (with the border bottom using the class current) as you are doing for the first one by default. You can try this:

$('.current').not(
             $(this)
               .closest('li')
               .addClass('current'))
.removeClass('current');

or just

$(this)
       .closest('li') //Get to the parent li
       .addClass('current') //add the class current
       .siblings('.current') // select the sibling with the same class  (previous selection)
       .removeClass('current'); //remove the class from there

Demo

1 Comment

@user2401856 You are welcome. Probably you should rephrase your questions. That is a bit confusing.. :)

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.