๐๐ฎ๐ ๐ฎ๐ฏ: ๐ ๐ฎ๐๐๐ฒ๐ฟ๐ถ๐ป๐ด ๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐๐๐ฒ๐ป๐๐
Day 23 of my MERN stack journey. I finished Lecture 8 from Apna College. I studied event listeners and the event object.
The event object contains data about an action.
- e.type tells you the event name.
- e.target tells you which element was clicked.
addEventListener is the professional way to handle events.
- It lets you add multiple functions to one element.
- It avoids overwriting old code.
removeEventListener stops an action.
- You must store the function in a variable first.
- This allows the browser to find the reference.
I built a Dark Mode and Light Mode toggle.
- I used a button.
- I added a click listener.
- I used a variable to track the current mode.
- I swapped CSS classes with classList.add and classList.remove.
I finished all DOM and Event basics. Tomorrow I build a mini project. I will practice clean code.
Did you use inline styles or CSS classes for your toggle? Do you use e.target for complex forms?
Source: https://dev.to/ali_hamza_589ec7b3eb6688d/day-23-of-leaning-mern-stack-5f8k