views:

90

answers:

6

Hi,

General javascript question here, which would also be good to know how(if possible) to do in jquery.

Can you trigger a click event when hovering over an item?

I know there will be people asking why, but please just humour me.

Many thanks, C

+4  A: 

Take a look at the trigger function:

$(someElement).trigger('click');
Darin Dimitrov
Excellent. Did a wee write up over here for anyone interested...http://blog.clintonbeattie.com/monitor-hovered-items-in-google-analytics/
Model Reject
+5  A: 

Just use click()

$(selector).click();

Or, alternatively just move your click() code out into a common function and call that from hover().

James Wiseman
+1  A: 

Quite simply:

$(selector).mouseenter(function() { $(this).click() });
Felix
A: 
$('#selector').bind('mouseover',function(){

/*DO WHAT YOU WANT HERE*/


});

that should do the trick

Jean
A: 

jQuery can trigger 'click' all object except tag a

let's try this code on console and see what happen on this page

$('a').bind('mouseover', function(){ 
    $(this).trigger('click'); 
    console.log('hover'); // let me know when it hovering <a>
});
ilumin
A: 
$('myselector').hover(function(){  
    $(this).trigger('click');  
}); 
Mark Schultheiss