Moose
Moose

Reputation: 152

What is the best way to get a Meta Element's Attribute Value in JS?

Something like this:

this.token = document.getElementById("token").getAttribute("content");

Even better, get the meta element by Name

Upvotes: 0

Views: 201

Answers (1)

Matthew James Davis
Matthew James Davis

Reputation: 12295

Try this:

document.querySelector('meta[name="name"]').getAttribute("content");

Upvotes: 2

Related Questions