开发者

How to call addClass() on all body elements using jQuery?

开发者 https://www.devze.com 2023-02-21 15:40 出处:网络
I want to call .addCla开发者_Go百科ss on all elements that are direct children of body. How would I do this?It\'s a bit unclear what you mean. This will call it on all <body> tags (hopefully you

I want to call .addCla开发者_Go百科ss on all elements that are direct children of body. How would I do this?


It's a bit unclear what you mean. This will call it on all <body> tags (hopefully you only have one):

$("body").addClass("some-class")

If you need to call it on all descendants of body, i.e. all elements:

$("body *").addClass("some-class")

Or, if you want to call .addClass on all elements that are direct children of body:

$("body > *").addClass("some-class")


Use this instead

$("body").children().addClass("some-class");
0

精彩评论

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