开发者

How to simplify this jQuery selector?

开发者 https://www.devze.com 2023-03-09 09:14 出处:网络
I am using this: $(this).parent(\'label\').parent(\'li\').parent(\'ul\').find(\'img\').removeClass(\'selectedRadio\');

I am using this:

$(this).parent('label').parent('li').parent('ul').find('img').removeClass('selectedRadio');

Instead of using parent 3 times how can I cond开发者_StackOverflow社区ense it?


Use closest instead of chaining parents:

$(this).closest('ul').find('img').removeClass('selectedRadio');


$(this).parents('ul:first').find('img').removeClass('selectedRadio');

Just find the first UL and then remove the images.


$("ul > li > label img.selectedRadio", this).removeClass('selectedRadio');

or just

$("ul > li > label img", this).removeClass('selectedRadio');
0

精彩评论

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