JQuery - Add css class to List

css, jquery, list, unordered

Solution

Try this:

$(".meuble-tab").parent("li").addClass("active");

For reference, please see parent( [expr] ):

Get the direct parent of an element. If called on a set of elements, parent returns a set of their unique direct parent elements.

You may use an optional expression to filter the element(s). If there is no parent, returns a jQuery object with a length of 0.

Problem

I have the following HTML : ``` <li> <a class="meuble-tab" href="#">Meuble</a> </li> ``` i need to achieve the following: ``` <li class="active"> <a class="meuble-tab" href="#">Meuble</a> </li> ``` Using Jquery I am at the point where i can get to the $(".meuble-tab") How do I get to its parent "li" to do the addClass("active")?

Original source