To dynamically load content, you can make an AJAX call using XMLHttpRequest() .
In this example, the URL is passed to the loadPage() function, which returns the loaded content.
<!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript"> function loadPage(href) { var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", href, false); xmlhttp.send(); return xmlhttp.responseText; } </script> </head> <body> <div onClick="document.getElementById('bottom').innerHTML = loadPage('hello-world.html');">Home</div> <div id="bottom"></div> </body> </html>
When the div element containing the text "Home" is clicked, it sets the html of the div element with the identifier "bottom" to the content found in the document "hello-world.html" in the same relative location.
Hi-world.html
<p>hello, world</p>
Jason sturges
source share