I have a link ('a' tag).
I'm trying to click it using JavaScript.
While .click();
does well in Firefox and IE but it fails in Chrome.
(Chrome says the object does not have the click method).
Triggering the 'onclick' or redirecting to the 'href' won't do the job.
Any ideas on how to do this? Preferably I wouldn't get an entire library just for this.
In non-IE-browsers use dispatchEvent()
var event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0,
false, false, false, false,
0, null);
element.dispatchEvent(event);
should work in chrome
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