I am learning HTML and Javascript, and for an assignment I need to get a button to change an element to another HTML file.
Here is my code:
main.html
</head>
<script src="testscript.js"></script>
</head>
<body>
<button onclick="button1()">Function 1</button>
</body>
testscript.js
function button1(){
var value = confirm("Press anything");
if(value == 1){
document.getElementById("abc").innerHTML = "Ok";
window.location.assign("button1.html");}
}
button1.html
<body>
<p id="abc"></p>
</body>
So basically, button1() gets called from main.html and needs to change the value of an element in button1.html.
A similar example is illustrated here: (link). I have also tried outerHTML but it doesn't work either. Is this not possible? I can't find anything online.
Note: My html and js files have to be separated.
Any help is appreciated. Thanks.