Umair Q.
Umair Q.

Reputation: 1

JQuery add class to Parent <li> of <a> with href

So i have this code

<li>
<a href="./home.php"></a>
</li>

I want to add class active to <li>

But i want to add this class by selecting <a> with href ="./home.php" get to it's parent <li> and add class active.

The final code will look like this

<li class="active">
    <a href="./home.php"></a>
</li>

Upvotes: 0

Views: 2034

Answers (1)

Nenad Vracar
Nenad Vracar

Reputation: 122057

Try this DEMO

$('a[href="./home.php"]').parent('li').addClass('active');

Upvotes: 1

Related Questions