This has been driving me nuts! I\'ve searched and tried a bunch of suggestions that seem like they should work, so I must be doing something foolish.
$(docum
This is the correct code:
$(document).ready( function(){
$('.trigger').click(function(){
var link = $(this).attr("href");
$('#target').load( link + ' body' );
return false;
});
});
and it's better to have a basic html structure in target files like this:
<html>
<body>
Content
</body>
</html>
Maybe your links are created dynamically, use event delegation with .on()
:
$(document).ready(function(){
$('body').on('click', '.trigger', function () {
var link = $(this).attr("href");
$('#target').load(link);
return false;
});
});
References:
Maybe you just need to prevent the default action when you click a link or check the url.
Try this:
$(document).ready(function(){
$('.trigger').click(function(e){
e.preventDefault();
var link = $(this).attr("href");
$('#target').load(link);
});
});
Also there's an example