I want to insert a new h3 element having my name before the first paragraph in the HTML only by using javascript. I do not want to edit the HTML file or the CSS file for it. I have tried this code in the javascript file
let h3e = document.createElement("h3");
h3e.textContent("Student Name");
document.body.insertBefore(h3e, document.body.firstChild);
But it is not working
let h3e = document.createElement("h3");
h3e.textContent("Student Name");
document.body.insertBefore(h3e, document.body.firstChild);
<body>
<header>
<h1>Bumblebee</h1>
</header>
<main>
<h2>General description</h2>
<figure><img src="bee1.jpg" />
<figcaption>A common bumblebee extending its tongue towards a Heuchera inflorescence.
</figcaption>
</figure>
<p>Bumblebees vary in o about 40 mm longginger beast".</p>
<h2>Distribution and habitat</h2>
<p>Test data</p>
</body>
Bumblebees vary in o about 40 mm longginger beast".
tag – Ankit Sharma Mar 22 '21 at 06:31