I need to simulate a click on a button using jquery.
Regular Javascript MouseEvents (mousedown and mouseup) do work, but I want jquery.
I have the div in a jquery object: (just a reference)
it was defined like
var $button = $(document.getElementById("iframe")...);
$button -> <div id="1" class="2" role = "button"><b>Action</b></div>
I've tried with $button.click() and $button.trigger('click') but both don't work.
I've read this, but provides no answer to this question.
Try this:
var e = document.createEvent("MouseEvents");
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
$button[0].dispatchEvent(e);
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