How to manually trigger an event that I connected using jQuery?

How to manually trigger the click event on a button that I pre-connected using jQuery?

0
source share
3 answers

Use a trigger. (link to trigger documentation)

$("button:first").click(function () { update($("span:first")); }); $("button:last").click(function () { $("button:first").trigger('click'); update($("span:last")); }); function update(j) { var n = parseInt(j.text(), 10); j.text(n + 1); } 
+6
source

One way to do this:

$ ('# pSearch') press () ;.

pSearch is the identifier of the button I want to click.

+1
source

You can use the id or class name as a selector to select an item

Then you can do it as below

$ ("class name.") Press the button () ;.

$ ("# ID") click the button () ;.

it works with me and you can try it in the Chrome console

0
source

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


All Articles