Skip to content
Advertisement

Insert element before tag with vanilla JavaScript

JavaScript

I’m not very familiar with vanilla Javascript, always have worked with jQuery. I tried this so far, but that got the element in the middle of <head> and <body>.

JavaScript

Advertisement

Answer

It’s pretty simple. Using appendChild method it can be written as short as:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement