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"));
});
精彩评论