I am trying to create a website that's split into two interactive frames. If you click on a link on the left hand side, the left hand side reloads with new content, while the right hand side remains unchanged (and doesn't refresh).
If I click on a link at the top of the sidebar just once, it behaves fine. Once I click on the same link twice, though my navigation elements disappear.
This is my sidebar's content code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$.get("sidebar-navigation.html", function(data){
$(".sidebar-nav").html(data);
});
/*
Use $.on() to associate a click handler with any link nested under .sidebar-navigation,
even if the links are dynamically added to the page in the future (ie after a
$.get())
*/
$('body').on('click', '.sidebar-nav a', function() {
/*
Get the href for the link being clicked
*/
var href = $(this).attr('href');
/*
Issue a request for the html document
or resource at href and load the contents
directly into .sidebar if successful
*/
$('.sidebar-content').load(href);
/*
Return false to prevent the link's default
navigation behavior
*/
return false;
})
</script>
</head>
<body>
<div class="sidebar-content">
<div class="sidebar-nav">
</div>
<p>
My sidebar content
</p>
</div>
</body>
</html>