Skip to content

Instantly share code, notes, and snippets.

@mbarkley
Created February 12, 2018 16:59
Show Gist options
  • Save mbarkley/31f0cee37cddbf56249ae19c6d3b3dfb to your computer and use it in GitHub Desktop.
Save mbarkley/31f0cee37cddbf56249ae19c6d3b3dfb to your computer and use it in GitHub Desktop.
Event Firing POC
<!DOCTYPE>
<html>
<head>
<script>
function doClick() {
// May need cross-browser support
//var evt = document.createEvent("HTMLEvents");
var evt = new Event("change");
var element = document.getElementById("id-2");
evt.initEvent("change", false, true);
element.dispatchEvent(evt);
alert("finished");
}
</script>
</head>
<body>
<div id="id-1" onclick="doClick();" style="width:100;height:100;background:black">
</div>
<div id="id-2" onchange="alert('done');" style="width:100;height:100;background:red">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment