Skip to content

Instantly share code, notes, and snippets.

@onpaws
Created August 3, 2016 19:01
Show Gist options
  • Select an option

  • Save onpaws/f4539f48df874a5ee4611e7ff1a4d32c to your computer and use it in GitHub Desktop.

Select an option

Save onpaws/f4539f48df874a5ee4611e7ff1a4d32c to your computer and use it in GitHub Desktop.
simulate a click without jQuery (native fire event)
function eventFire(el, etype){
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
eventFire(document.getElementById('submitButton'), 'click');
//see commentary at http://stackoverflow.com/questions/2705583/how-to-simulate-a-click-with-javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment