Trigger event after parsing html page

I can programmatically go to the url, get the answer and parse it. But can I fire the javascript click event of the html element of this answer? For example, let the answer contain an element:

<div id="test">Click me</div>

And the page handles the click event, for example:

$("#test").on('click'..... etc.

So, is there a way I can fire this event after receiving an html response?

+4
source share
1 answer

DOM elements have .click ()

So something like this works:

 <body>
    <a href="" id="myLink">Test me!</a>
</body>

And you have the following:

// basic function to be called
function clickMe() {
  alert("Clicked!");
}

$(document).ready(function() {

  // click event handler
  $("#myLink").on('click', function() {
    clickMe();
  });

  // invoke the click
  $("#myLink").click();

});

Hope this helps.

0
source

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


All Articles