How to target body in javascript DOM event
13,708
Solution 1
You can use document.body
to get to it. To remove the class, you can use:
document.body.className = '';
This will change the contents of the class
attribute to be the empty string, so it will remove all the classes the element might have.
Solution 2
To remove class from 'body' tag use this:
document.body.removeAttribute('class');
Author by
Admin
Updated on July 18, 2022Comments
-
Admin almost 2 years
I would like to modify a style which looks like:
<body class="theme1">
I would like to target this body's class and make that to just
<body>
. The problem is that, even though I would normally find elements usingdocument.getElementById('someId')
or bytagName
in this case, I don't know how to find the target. -
Pouria Hemati over 3 yearsPlease don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.