JQuery将类添加到<a> with href

时间:2016-05-07 19:24:44

标签: jquery html css-selectors parent addclass

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>

1 个答案:

答案 0 :(得分:1)

试试这个DEMO

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