Cofey
Cofey

Reputation: 11404

How to get ID of HTML element?

So the code below will get the ID of the BODY elementL

var bodyId = document.body.id;

How can I get the ID of the HTML element using plain ole' JavaScript?

Upvotes: 2

Views: 35737

Answers (2)

Acorn
Acorn

Reputation: 50497

document.getElementsByTagName('HTML')[0].id

Upvotes: 4

icktoofay
icktoofay

Reputation: 129011

document.documentElement.id

Upvotes: 12

Related Questions