Skip to content

Instantly share code, notes, and snippets.

@olivx
Last active November 1, 2018 04:11
Show Gist options
  • Select an option

  • Save olivx/3cac0eada7a4853306d74192aba4128c to your computer and use it in GitHub Desktop.

Select an option

Save olivx/3cac0eada7a4853306d74192aba4128c to your computer and use it in GitHub Desktop.
vanilla java script simulando cick
/**
* Simulate a click event.
* @public
* @param {Element} elem the element to simulate a click on
*/
var simulateClick = function (elem) {
// Create our event (with options)
var evt = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
// If cancelled, don't dispatch our event
var canceled = !elem.dispatchEvent(evt);
};
var someLink = document.querySelector('a');
simulateClick(someLink);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment