开发者

Can I apply a class to a table row containing a link, rather than to the link itself?

The following code adds a class to a link and removes another class from the same link:

 $('a[href$="' + myStr + '"]').removeClass('yes').addClass('no');

The link appears in a table. How would I apply this change in class to the ROW that the link appears within in the table, rather than to the link itself? I've been开发者_如何学Python playing around with the 'parent' command however either that isn't it or I'm doing it wrong.

Thanks in advance for any help!


$('a[href$="' + myStr + '"]').closest('tr').removeClass('yes').addClass('no');


Try the :has() selector:

$('tr:has(a[href$="' + myStr + '"])').removeClass('yes').addClass('no');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜