0

Im trying to do something similar to this, but cant get it going.

EXAMPLE

What I want to do different is to search for a class similar to the example, but then add a class to the sub "a" tag. Something like this.

$("#tabAdm").closest('li[class^="tabAdmission"] > a').addClass('active_pat_tab');

It seemed simple, but like I said, cant get it to work.

4

1 回答 1

2

.closest()将为您提供所需的祖先引用,然后您需要使用后代遍历方法来找到所需的孩子

使用.children()

var xxx = $("#tabAdm").closest('li[class^="tabAdmission"]').children('a').addClass('active_pat_tab');

或者如果不是后代a的孩子- .find()tabAdmission

var xxx = $("#tabAdm").closest('li[class^="tabAdmission"]').find('a').addClass('active_pat_tab');
于 2013-10-31T10:15:04.720 回答