13 January 2023

In vanilla JavaScript, the equivalent of the jQuery click function would be the onclick property. The onclick property in JavaScript is an event property of HTML elements that allows you to specify a function to be called when an element is clicked. When you use onclick property in JavaScript it will overwrite any previous onclick function, you might want to look into addEventListener, it appends a function.

Source code viewer
  1. window.document.getElementById("element_id").onclick = function() {
  2. // Code to be executed when the event is triggered.
  3. };
Programming Language: Javascript