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
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');
});
References:
Comments
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
PSL
@user2401856 You are welcome. Probably you should rephrase your questions. That is a bit confusing.. :)