Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to call .addClass on all elements that are direct children of body. How would I do this?

like image 905
Rella Avatar asked Nov 28 '22 03:11

Rella


1 Answers

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")
like image 140
Håvard Avatar answered Dec 07 '22 22:12

Håvard