Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery - Add css class to List

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")?

like image 707
Murtaza Mandvi Avatar asked Jun 01 '26 13:06

Murtaza Mandvi


1 Answers

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.

like image 104
Andrew Hare Avatar answered Jun 03 '26 04:06

Andrew Hare