How do I trigger this inline functiononClick="showMenu('mnu_searches', event, 0, this)
using JQuery...if I hover over a.menu-arrow
? I need to trigger a click after the user has been hovering over the element for 2 seconds?
Any help would be greatly appreciated, Thanks
You can create and clear a 2 second timer, like this:
$("a.menu-arrow").hover(function() {
$.data(this, "timer", setTimeout($.proxy(function() {
$(this).click();
}, this), 2000));
}, function() {
clearTimeout($.data(this, "timer"));
});
You can give it a try here. By using $.data()
we're storing a timeout per element to avoid any issues and clear the correct timer. The rest is just setting a 2 second timer when entering the element, and clearing it when leaving. So if you stay for 2000ms, it fires a .click()
, if you leave it stops clear the timer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With