0

This code is for the purpose of replace content inside a div using ?sub=1 as a trigger.
I'm pretty new to the javascript world, I created this code but I'm missing something, and I can not figure out what
If sub is =1, change the content inside the div to "other content"

var url = new URL(window.location);
var sub = url.searchParams.get("sub");

if(sub == 1) {
    document.getElementById("element").innerHTML = "<span>Something</span>\n<div>Something</div>"
}
<div id="element">Content</div>
MrStatic
  • 53
  • 4

0 Answers0