8000 currentTarget_target.js · last-endcode/JavaScript-DOM@3e9608f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e9608f

Browse files
committed
currentTarget_target.js
1 parent 978e7b7 commit 3e9608f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

21_currentTarget_target.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// currentTarget - always refers to the element
2+
// - to which the event handler has been attached to
3+
// target - identifies the element on which the
4+
// - event occured
5+
6+
const btns = document.querySelectorAll('.btn');
7+
8+
// forEach()
9+
btns.forEach(function (btn) {
10+
btn.addEventListener('click', function (e) {
11+
// if click button will add color black for
12+
// all button element include h1 and strong element be black color
13+
e.currentTarget.style.color = 'black';
14+
console.log(e.currentTarget);
15+
// but if target, will effect on element yg di click
16+
// and not effect all element just element click will change
17+
// but if main click all element will change
18+
e.target.style.textTransform = 'lowercase';
19+
console.log(e.target);
20+
});
21+
});

0 commit comments

Comments
 (0)
0