Jquery simulates a click on a <div role = button>

I need to simulate a click on a button using jquery.

Regular Javascript MouseEvents (mousedown and mouseup) work, but I want jquery.

I have a div in a jquery object: (just a link)

he was defined as

var $button = $(document.getElementById("iframe")...); 

$button โ†’ <div id="1" class="2" role = "button"><b>Action</b></div>

I tried with $button.click() and $button.trigger('click') , but both of them do not work.

I read this , but does not give an answer to this question.

+2
source share
1 answer

Try the following:

 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); 
+7
source

Source: https://habr.com/ru/post/982382/


All Articles