开发者

jquery load based on href

I am having a link

<a id="test" href="text.php">test</a>

I have the following jquery code

    $("#test").live("click", function(){                       
             $("#myDiv").load($("#text").attr("href"));         
        });

trying to load the href of #test inside myDiv.

But of course when click, start .load the href AND the browser changes 开发者_如何学运维to text.php.

Is there any way to achieve this.

Thanks


Yes, add return false; to your click handler:

$("#test").live("click", function(){                       
  $("#myDiv").load($("#text").attr("href"));         
  return false;
});


There's a jQuery-specific way of doing this but I forget what it is :-) but you can add return false to your anonymous function:

$("#test").live("click", function(){                       
  $("#myDiv").load($("#text").attr("href"));    
  return false;     
});

which should prevent the default action happening.


You can also use it

$("#test").live("click", function(e){    
      e.preventDefault();                   
      $("#myDiv").load($("#text").attr("href"));    

    });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜