In my website I’ve created a layout in which a <div> is a menu that lists some links ad a <div> that acts as main page in where every link opened is shown.
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.linkpage').bind('click', function(e) {
var url = $(this).attr('href');
$('#main').load(url);
e.preventDefault();
});
});
</script>
</head>
<body>
<div id="menu">
<a href="Page1.php" class="linkpage">Page1</a>
<a href="Page2.php" class="linkpage">Page2</a>
</div>
<div id="main">
</div>
</body>
This is the colmplete page and opens link in the targeted div (main) when clicked. The problem happens when I click a link that is positioned in the main <div>:
<a href='Page2.php' class='linkpage'>ClickMe.</a>
This is not triggered in the same div, but it opens full page, like a target='_top', instead opening itself in the same , maintaining the menu on the left of the page itself. What I’ve to add in the script to have the links opened in the proper target?
Thanks in advance.
Change
.bind(to.live(in your jQuery.That way it will act on all links, even ones that are added to the DOM after the script has run. The way it is right now, it will only act on links that are in the DOM at the time the script was run.