View Single Post
Old 09-27-2008, 07:29 PM   #2 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Your code will execute as soon as the browser sees it, but at that time there are no <a> elements to attach the click function to! You need to wait until the HTML document is all downloaded to safely attach event handlers like this.

JavaScript Code:
jQuery(function(){

  $("a").click(function(event){
    alert("As you can see, the link no longer took you to jquery.com");
    event.preventDefault();
  });

});
Salathe is offline  
Reply With Quote