Tip: Click lines to highlight, hold ctrl/cmd to multi-select
JavaScript event delegator template (10-Feb @ 13:48)
Template for event delegation
Syntax Highlighted Code
- window.onload = function () { var navigation = document.getElementById("some_element_high_up_in_the_hierarchy");
- navigation.onclick = function (evt) {
- // Event tweaks, since IE wants to go its own way...
- var event = evt || window.event;
- var target = event.target || event.srcElement;
- if(target.className && target.className==='someClass') {
- //do your stuff here
- }
- }
- };
Plain Code
window.onload = function () { var navigation = document.getElementById("some_element_high_up_in_the_hierarchy");
navigation.onclick = function (evt) {
// Event tweaks, since IE wants to go its own way...
var event = evt || window.event;
var target = event.target || event.srcElement;
if(target.className && target.className==='someClass') {
//do your stuff here
}
}
};