Skip to content

Instantly share code, notes, and snippets.

@ddbeck
Created March 22, 2021 18:00
Show Gist options
  • Save ddbeck/5410a42a84789b1fe6942f1b81f03fad to your computer and use it in GitHub Desktop.
Save ddbeck/5410a42a84789b1fe6942f1b81f03fad to your computer and use it in GitHub Desktop.
<html>
<head>
<title>api.EventTarget.addEventListener.options.signal</title>
</head>
<body>
<p id="target">clickable: <span id="state">yes</span></p>
<p id="notice">FAIL</p>
<script>
var controller = new AbortController();
var target = document.getElementById("target");
var notice = document.getElementById("notice");
var state = document.getElementById("state");
function turnOffClick() {
state.firstChild.nodeValue =
state.firstChild.nodeValue === "yes" ? "no" : "FAIL";
}
target.addEventListener("click", turnOffClick, {
signal: controller.signal,
});
target.click();
controller.abort();
target.click();
if (state.firstChild.nodeValue === "no" && controller.signal.aborted) {
notice.innerHTML = "PASS";
} else {
notice.innerHTML = "FAIL";
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment