Last active
July 9, 2018 05:08
-
-
Save JiaLiPassion/35f5ffa53064867fc069c685a8f596db to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Import stylesheets | |
import './style.css'; | |
// Write Javascript code! | |
const appDiv = document.getElementById('app'); | |
appDiv.innerText = 'App'; | |
// register a event handler named 'highlight' | |
appDiv.addEventListener('highlight', function(event) { | |
appDiv.innerText = 'App highlighted'; | |
}); | |
function highlight(elem) { | |
elem.classList.add('highlight'); | |
var event = document.createEvent('CustomEvent'); | |
event.initCustomEvent('highlight'); | |
elem.dispatchEvent(event); | |
}; | |
appDiv.addEventListener('click', function(event) { | |
highlight(event.target); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment