user1679941
user1679941

Reputation:

With javascript how can I identify the HTML tag?

I had another question similar to this but the answers seemed to miss out that I was trying to find the <HTML> tag and modify it.

They suggested:

elem.className = elem.className.replace(/\blight\b/," dark ");

But with javascript how can I get the <HTML> tag as the elem variable?

Upvotes: 0

Views: 51

Answers (3)

melc
melc

Reputation: 11671

The following code returns the html element

document.documentElement

Upvotes: 1

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

to get <html> tag you could just do:

var elem = document.getElementsByTagName("html")[0];

or

var elem = document.querySelector("html");

or

var elem = document.body.parentNode;

Upvotes: 2

Artyom Neustroev
Artyom Neustroev

Reputation: 8715

var htmlTag = document.getElementsByTagName("html")[0]

Upvotes: 0

Related Questions