Categories
JavaScript Answers

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

Spread the love

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

For instance, we write

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

to select the meta element with the property attribute containing video and has the content attribute with document.head..querySelector from the head element.

Then we get the content attribute from the selected element with the content property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *