I want to create a <button> that when clicked will open a URL in a new tab.
This is easy to achieve in pure HTML, but the catch is that the <button> is dynamically generated, thus this has to be done in JavaScript.
This is the code I used to create a <button> so far using JavaScript and HTML DOM:
<body>
<div id = 'only_div'>
</div>
<script>
var btn=document.createElement("button");
btn.innerText = "Click me";
document.getElementById("only_div").appendChild(btn);
</script>
</body>
In this existing code, I just want to add that when clicked, a URL (for example http://www.stackoverflow.com) will open in a new tab.