I am trying to load an html file using the jQuery .load function (https://api.jquery.com/load/).
I have created this function in script.js
:
function loadPost(file) {
console.log(file);
$("#content").load(file);
};
This is what index.html
looks like:
<html>
<head>
<script src="js/jquery.js"> </script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<script>
loadPost("post1.html"); // does not work
</script>
<header>
// function call works
<a id="go_home_link" onclick="loadPost('post1.html')" href="#">
Go home
</a>
</header>
</body>
</html>
I have also tried using loadPost("'post1.html'")
, but that doesn't work either. Any ideas why using the javascript block would not work, but call the function inline in another element does work?
Thanks