Triggering Click Event will Retrun true but will not work

Here is a target for the test:

https://demo.wpjobboard.net/wp-login.php

I need to click on login button using javascript and I use this peice of code:

document.querySelectorAll('[id="wp-submit"]')[0].dispatchEvent(new Event('click'));

I need to use dispatchEvent because the click event here can be replaced with any event.

It will return true but it won’t work. where is the problem?

2 thoughts on “Triggering Click Event will Retrun true but will not work”

  1. query selector all will return a list of dom nodes, you should probably use just document.querySelector, but even better probably is document.getElementById since you are querying via ID.

    Addtionally there is a simpler click event method available. What about something like this:

    function checkBox(){
        document.getElementById('wp-submit').click()
    }
    <div>
      <input id="wp-submit" type="checkbox">
      <button type="button" onClick="checkBox()">
        Click me to check the box
      </button>
    </div>
    Reply

Leave a Comment