Sometimes, we want to add meta tag in JavaScript.
In this article, we’ll look at how to add meta tag in JavaScript.
How to add meta tag in JavaScript?
To add meta tag in JavaScript, we call createElement
.
For instance, we write
const meta = document.createElement("meta");
meta.httpEquiv = "X-UA-Compatible";
meta.content = "IE=edge";
document.head.appendChild(meta);
to call createElement
to create a meta element.
Then we set the http-equiv
attribute with
meta.httpEquiv = "X-UA-Compatible";
We set the content
attribute with
meta.content = "IE=edge";
And we append it as the last child of the head element with
document.head.appendChild(meta);
Conclusion
To add meta tag in JavaScript, we call createElement
.