8000 propogation · last-endcode/JavaScript-DOM@b88af94 · GitHub
[go: up one dir, main page]

Skip to content

Commit b88af94

Browse files
committed
propogation
1 parent 3e9608f commit b88af94

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

22_propogation_bubbling_capturing.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// allows select dynamic elements
2+
// event propogation - order the events are fired
3+
// event bubbling - clicked element first then bubles up --
4+
// default
5+
// event capturing - fires at the root and fires until
6+
// reaches target
7+
8+
const list_items = document.querySelector('.list-items');
9+
const container = document.querySelector('.container');
10+
11+
function showBubbling(e) {
12+
// output all element list-items and child like li.item
13+
console.log('current target :', e.currentTarget);
14+
//output only target element clicked example: click link show only a href
15+
console.log('target : ', e.target);
16+
// checked
17+
if (e.target.classList.contains('link')) {
18+
console.log('your clicked link');
19+
}
20+
}
21+
22+
// if link will not click here
23+
function stopPropogation(e) {
24+
e.stopPropogation;
25+
console.log('not click');
26+
}
27+
28+
// container.addEventListener('click', showBubbling);
29+
list_items.addEventListener('click', showBubbling);

0 commit comments

Comments
 (0)
0