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
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
Take a look at the trigger function:
$(someElement).trigger('click');
Just use click()
$(selector).click();
Or, alternatively just move your click() code out into a common function and call that from hover().
Quite simply:
$(selector).mouseenter(function() { $(this).click() });
$('#selector').bind('mouseover',function(){
/*DO WHAT YOU WANT HERE*/
});
that should do the trick
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>
});
$('myselector').hover(function(){
$(this).trigger('click');
});