开发者

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');

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜