Reputation: 97
I want to add a class to a link when it is clicked, but I can't use:
$('a.someLink').click(function() {
// code
});
since click seems to detect when a user clicks and lets go of the mouse clicker on an element. I need to add the class as soon as the user has clicked on the element, even before he lets ago of the mouse clicker and after he lets go I need the class to be removed.
Basically I'm trying to mimic css's active state on links:
a:active
How can this be done?
Upvotes: 1
Views: 313
Reputation: 166
With $('a.someLink').mousedown()
you can add the class, and then with $('a.someLink').mouseup()
you can remove it.
Upvotes: 1
Reputation: 69905
Try mousedown
which is triggered even before click
event.
$('a.someLink').mousedown(function() {
// code
});
Upvotes: 0
Reputation: 21366
$('a.someLink').mousedown(function() {
//code
});
http://api.jquery.com/mousedown/
Upvotes: 1
Reputation: 15666
You can use $('a.someLink').mousedown(function() { //code });
instead
Upvotes: 3