[jQuery] Re: how to bind one action to multiple events?
Update: A more accessible hover function. I did my homework, then did this: // a more accessible hover function jQuery.fn.extend({ hover: function(fnOver, fnOut) { return this.bind('mouseenter mouseover focus', fnOver).bind('mouseleave mouseout blur', fnOut); } }); (Works with the built-in .hover event). Only tested in IE7 and FF2.0.0.11 Cherry. On Feb 4, 7:31 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Trying to do a simple a: rollover - but, being a perfectionist, I want the rollover behaviour triggered by mouseover OR focus. And then, of course, on mouseout OR blur.
[jQuery] Re: how to bind one action to multiple events?
With jQuery 1.2.2 you can now bind multiple events at once. Just separate them with a space. I'd also suggest using the new mouseenter and mouseleave events. $('a') .bind(mouseenter focus mouseleave blur, function(event) { console.log(event.type); }); -- Brandon Aaron On Feb 3, 12:31 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... at least, that's what I think I need to do! Trying to do a simple a: rollover - but, being a perfectionist, I want the rollover behaviour triggered by mouseover OR focus. And then, of course, on mouseout OR blur. I tried sticking 2 events together with a | , without success. However, this is my first attempt at 'binding' so might have done the whole thing wrong. How should I do this? Thanks :) Cherry.
[jQuery] Re: how to bind one action to multiple events?
$('mySelector').mouseover(function() { // do something on mouseover and focus }) .focus(function(){ // trigger the mouseover event on focus $(this).trigger('mouseover') }); On Feb 4, 7:31 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... at least, that's what I think I need to do! Trying to do a simple a: rollover - but, being a perfectionist, I want the rollover behaviour triggered by mouseover OR focus. And then, of course, on mouseout OR blur. I tried sticking 2 events together with a | , without success. However, this is my first attempt at 'binding' so might have done the whole thing wrong. How should I do this? Thanks :) Cherry.
[jQuery] Re: how to bind one action to multiple events?
Thanks a million, Brandon - and for your blog, which I'm keeping permanently open! Doing as you suggested above wouldn't put the 'up' image back on mouseout (my syntax was probably wrong), though I did manage to get it working by doing it the long way . Then I rewrote the core :/ hover:function(fnOver,fnOut){return this.bind('mouseenter focus',fnOver).bind('mouseleave blur',fnOut);} Hope it goes in the next version! More effusion ;) Cherry On Feb 3, 9:30 pm, Brandon Aaron [EMAIL PROTECTED] wrote: With jQuery 1.2.2 you can nowbindmultipleevents at once. Just separate them with a space. I'd also suggest using the new mouseenter and mouseleave events. $('a') .bind(mouseenter focus mouseleave blur, function(event) { console.log(event.type); }); -- Brandon Aaron On Feb 3, 12:31 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Trying to do a simple a: rollover - but, being a perfectionist, I want the rollover behaviour triggered by mouseover OR focus. And then, of course, on mouseout OR blur.
[jQuery] Re: how to bind one action to multiple events?
Ooohh, that's neat! Blimey, I'm learning a lot Thanks, Hamish :) On Feb 3, 8:01 pm, Hamish Campbell [EMAIL PROTECTED] wrote: $('mySelector').mouseover(function() { // do something on mouseover and focus}) .focus(function(){ // trigger the mouseover event on focus $(this).trigger('mouseover') }); On Feb 4, 7:31 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Trying to do a simple a: rollover - but, being a perfectionist, I want the rollover behaviour triggered by mouseover OR focus. And then, of course, on mouseout OR blur.