Monday, 18 July 2011

Preventing the default behaviour of a page

Assuming we have a long page, and we have a link that is used for other purposesother than a
hyperlink. If you clicked on it, it will bring you to the top of your page. The reason
of this behavior is because of the # symbol. To solve this problem, we need to cancel the default
 behavior by doing this:
$('#close').click(function(e){  
     e.preventDefault();
}); 

OR

$('#close').click(function(){  
    return false;
}); 

<a href="#" id="close"></a>

No comments:

Post a Comment