如何在jQuery中选择“ this”内的元素?


94

我知道我可以这样选择一个元素:

$("ul.topnav > li.target").css("border", "3px double red");

但是我该怎么做:

$(this > li.target).css("border", "3px double red");

Answers:



9

我用它来得到父母,类似地给孩子

$( this ).children( 'li.target' ).css("border", "3px double red");

祝好运

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.