How to get the information from a meta tag with JavaScript?

Spread the love

Sometimes, we want to get the information from a meta tag with JavaScript.

In this article, we’ll look at how to get the information from a meta tag with JavaScript.

How to get the information from a meta tag with JavaScript?

To get the information from a meta tag with JavaScript, we use querySelector.

For instance, we write

const content = document.head.querySelector(
  "[property~=video][content]"
).content;

to select the meta tag with property video from the head element.

And then we get the content attribute with content.

Conclusion

To get the information from a meta tag with JavaScript, we use querySelector.

Leave a Reply

Your email address will not be published.