tags:

views:

25

answers:

2

Hi,

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

+3  A: 

Yes, add return false; to your click handler:

$("#test").live("click", function(){                       
  $("#myDiv").load($("#text").attr("href"));         
  return false;
});
thenduks
Thanks, silly me
ntan
+2  A: 

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.

richsage