-
-
Save biologyscience/295be8fc18a36ed9c73bc67bcdfc36f8 to your computer and use it in GitHub Desktop.
send info with events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = document.getElementById('a'); | |
const aVal = parseInt(a.value); | |
const myEvent = new CustomEvent('myEvent', {detail: aVal}); | |
document.dispatchEvent(myEvent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('myEvent', (data) => | |
{ | |
const b = document.getElementById('b'); | |
const aVal = data.detail; | |
b.value = aVal + 5; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="a.js" defer></script> | |
<script src="b.js" defer></script> | |
</head> | |
<body> | |
<input id="a" type="text" value="10"> | |
<input id="b" type="text"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment