Change Links within DIV to use JQuery Load
I am trying to make a script whereby cetain links use JQuery load instead
This does not work.
开发者_高级运维function inload() {
$('#sausage').load(this.attr('href') + ' #sausage');
return false;
}
I think the problem is with my this.attr('href')
but I require some advice.
Any ideas?
Marvellous
$("a").live("click",function(e){ //.live not .click so the function will also work on the newly loaded content
e.preventDefault(); //prevent the default action of clicking the link
var href = $(this).attr("href"); //grab the links href
$("body").load(href,callback); //load the contents of the href info the body of the page
});
//added a callback for running after the content has loaded if required
function callback(){
alert("content loaded");
}
Should be
$('#sausage').load($(this).attr('href')+'#sausage');
or
$('#sausage').load(this.href+'#sausage');
To get at the href
you can simply do this.href
this assumes you are actually using an <a/>
tag, and this
is a Dom Element
function inload() {
$('#sausage').load(this.href + ' #sausage');
return false;
}
Otherwise use $(this).attr('href');
精彩评论