How to fake click to activate an onclick method with JavaScript?

Sometimes, we want to fake click to activate an onclick method with JavaScript.

In this article, we’ll look at how to fake click to activate an onclick method with JavaScript.

How to fake click to activate an onclick method with JavaScript?

To fake click to activate an onclick method with JavaScript, we call the click method.

For instance, we write

document.getElementById("link").click();

to get the element we want to click with getElementById.

Then we call click on it to trigger the click.

Conclusion

To fake click to activate an onclick method with JavaScript, we call the click method.