Sometimes, we want to create a style tag tag with JavaScript.
In this article, we’ll look at how to create a style tag tag with JavaScript.
How to create a style tag tag with JavaScript?
To create a style tag tag with JavaScript, we call createElement
.
For instance, we write
const ss = document.createElement("link");
ss.type = "text/css";
ss.rel = "stylesheet";
ss.href = "style.css";
document.head.appendChild(ss);
to call createElement
to create a link element.
Then we set its attributes by setting its properties.
Next, we call document.head.appendChild
to append the link element as the last child of the head element.
Conclusion
To create a style tag tag with JavaScript, we call createElement
.