<!DOCTYPE html>
<html lang="en-US">
<body>
<h2>Heading</h2>
<p>Click on the button to insert the text before the beginning of the h2 tag.</p>
<button onclick="myFunction()">Click Me</button>
<script>
var target = document.getElementsByTagName("h2")[0];
var text = "This is text only";
function myFunction(){
target.insertAdjacentText("beforebegin", text);
}
</script> </body>
</html>