I have this code :
<!DOCTYPE html>
<body>
<div id=div1 style="display:block;">
<p id="intro">Hello World!</p>
<p>This example demonstrates the <b>getElementById</b> method!</p>
</div>
<div id=div2 style="display:none;">
<p id="intro">Hello World again!</p>
<p>This example demonstrates the <b>getElementById</b> method!</p>
</div>
<button type="button" onclick="func()">Change div</button>
<script>
function func() {
x = document.getElementById("div1");
x.style.display = "none";
x1 = document.getElementById("div2");
x1.style.display = "block";
}
</script>
</body>
It basically displays div2 on button click.
This works fine when div2 and div1 are in same file. I want div2 to be in different file and be displayed when we click the button without changing the url.
One way to achieve this is by using iframes and changing the url(in which div2 is there) of iframe on button click.
Is there any other way to achieve this?
I am very new to html and javascript so an explation with answer will help a lot. Thanks!