Reputation: 7971
I have click function on a tag. I want to bind mouseover event on same element. It this possible with .bind method. fiddle
$(function(){
$('a').click(function(){
alert(0);
})
$('a').bind('mouseover')
})
<a href="#">Jitender</a>
Upvotes: 0
Views: 64
Reputation: 2248
$(function(){
$('a').on('click mouseover', function() {
alert(0);
return false;
});
});
Upvotes: 2
Reputation: 19066
Yes, like this:
$('a').bind('mouseover', function () {
alert(0);
});
Also, bind()
is outdated, if you are using a newer version of jquery (1.7+) you should be using on()
instead.
As it's hard to see both mouseover and click events that create an alert (since the alert from the mouseover
would prevent you from ever clicking on it), the following will allow you to see both events working better:
$('a').on('mouseover click', function(){
$(this).toggleClass("test");
});
Upvotes: 0
Reputation: 337560
Assuming you want to bind the same handler to the click
and mouseover
event you can try this:
$('a').on('click mouseover', function(e) {
e.preventDefault();
alert('0');
});
Note the usage of on
is preferred over bind
in jQuery 1.7+.
Upvotes: 3
Reputation: 35793
Yes. Just bind the mouseover following the click binding:
$('a').click(function(){
alert(0);
}).bind('mouseover', function() {
$(this).css('background-color', 'red'); // To show it working
});
Upvotes: 1
Reputation: 25197
You should use the on
keyword.
$('a').on('mouseover', function() { alert(1);})
Per the jQuery documentation:
"As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document."
Upvotes: 1
Reputation: 104775
Sure!
$('a').mouseover(function() {
alert("Moused!");
});
Demo: http://jsfiddle.net/R7qrC/2/
Upvotes: 1