Detect when link is activated - either by click or tab and enter

vdhant picture vdhant · Apr 23, 2009 · Viewed 11.3k times · Source

Just wondering if anyone knows of a way that wiring up jquery to run a function for when a user clicks on a link or tabs to a link and hits enter.

I want to intercept that activation of a link and perform an action before the page is changed, but I want to do it in either case.

Answer

pjesi picture pjesi · Apr 23, 2009

The 'click' event will fire in both cases, this will get you what you want:

$('a').click(function(){
    alert('perform action here');
});