jquery prevent focus on click
Posted
by DA
on Stack Overflow
See other posts from Stack Overflow
or by DA
Published on 2010-03-16T21:02:56Z
Indexed on
2010/03/16
21:11 UTC
Read the original article
Hit count: 294
I have this sample code:
$myTrigger
.click(function(e){
alert('click');
})
.focus(function(e){
alert('focus');
$(this).click()
})
The intent is that I want something to happen when you click on $myTrigger. If, on the other hand, you tab onto it via the keyboard (ie, focus) I want the exact same thing to happen, so I ask it to click.
The catch is if I click on it, it also focuses. So both alerts are going off.
Is there a way to prevent the focus event from going off when clicking?
© Stack Overflow or respective owner