Event Listeners in JavaScript | JavaScript Events Tutorial
Dave Gray
@davegrayteachescodeAbout
Web Development tutorials with full courses on HTML, CSS, JavaScript, React, Node.js and more! My goal is to help you learn how to build the web. Teaching helps me learn, too. I work full-time as a Solutions Architect / Developer and part-time as a university web dev instructor. Thank you for subscribing, supporting my channel and sharing the videos you think may help others. Keep striving for progress over perfection. And a little progress every day goes a very long way. Milestones: July 20, 2020 - 1st video Jan 1, 2021 - 1k subs April 2021 - 4k watch hours Nov 2021 - 10k subs Jan 21, 2022 - Video at 100k views Feb 16, 2022 - 100k watch hours Feb 19, 2022 - 1m views Dec 13, 2022 - 100k subs Dec 2022 - Over 1m views in 1 month April 7, 2023 - 10m views May 26, 2023 - 1m watch hours Sept 22, 2023 - Video at 1m views Dec 25, 2023 - 250k subs
Latest Posts
Video Description
Web Dev Roadmap for Beginners (Free!): https://bit.ly/DaveGrayWebDevRoadmap In this video we'll learn about Event Listeners in JavaScript with addEventListener. We'll also explore Event Bubbling, Event Capturing, Event Propagation, and Prevent Default Behaviors. We'll look at the click event, readystatechange event, mouseover & mouseout events, and the submit event while using both named and anonymous functions as event handlers. We'll also work with the add, remove, and toggle methods of a classList. Let's get started! ▶ This video is part of the JavaScript Tutorials for Beginners Playlist found here: https://www.youtube.com/playlist?list=PL0Zuz27SZ-6Oi6xNtL_fwCrwpuqylMsgT ✅ Quick Concepts outline: JavaScript Event Listeners (00:00) Intro (0:20) Insure the DOM is available to interact with (1:30) How to load your script for DOM interaction (3:30) Syntax: addEventListener(event, function, useCapture) (4:50) Using a function name in the event listener (5:55) Removing a function with a name: removeEventListener() (6:50) Using an anonymous function in the event listener (8:50) Listening for the readystatechange event (10:30) Constructing an initApp() function (13:30) Event Bubbling (16:00) Event Capturing (17:00) Event Propagation and stopPropagation() (21:45) event.target usage (25:05) classList, add, remove, and toggle (34:50) Listening for a HTML Form submit event (36:20) HTML Form default behavior (37:00) Prevent default behavior with event.preventDefault() 🚀 Source Code Files: 🔗 HTML: https://gist.github.com/gitdagray/7d1676f2503c987fe22e2a8c10926426 🔗 CSS: https://gist.github.com/gitdagray/cf6256c62fad399e056d8e7187950c73 Note: You'll need to change display settings in the CSS for each example. 📚 Further Reading: MDN Web Docs: Introduction to events: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events Event reference: https://developer.mozilla.org/en-US/docs/Web/Events addEventListener: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener readyState: https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState Eloquent JavaScript Chapter 15: https://eloquentjavascript.net/15_event.html 📺 More Beginner JS Videos: freeCodeCamp: https://youtu.be/PkZNo7MFNFg Traversy Media: https://youtu.be/hdI2bqOjy3c The Net Ninja: https://youtu.be/iWOYAxlnaww ✅ Follow Me: Github: https://github.com/gitdagray Twitter: https://twitter.com/yesdavidgray LinkedIn: https://www.linkedin.com/in/davidagray/ Blog: https://yesdavidgray.com Reddit: https://www.reddit.com/user/DaveOnEleven #event #listeners #javascript
Transform Your Space Today
AI-recommended products based on this video

RoboSeal Rechargeable Mason Jar Vacuum Sealer for Mason Jars Wide and Regular, One Touch Vacuum Sealer for Jars, 10 Lids Included, Digital Battery Indicator, As Seen on TV

2 Pack Outdoor Solar Firework Lights, 240 LED Solar Powered Hanging Lights Outdoor Waterproof Hanging Fairy Garden Lights Landscape Lights(Warm White)
![Command Medium Picture Hanging Strips [Removable]: 12 Pairs (White)](https://m.media-amazon.com/images/I/61IChX1hbML._AC_UL960_FMwebp_QL65_.jpg)
Command Medium Picture Hanging Strips [Removable]: 12 Pairs (White)

Camping String Lights Outdoor, 6 in 1 Outdoor Waterproof Solar/USB Rechargeable Retractable Portable Stowable String Light with 8 Modes (42ft), Tent Lights for Camping, Hiking, Yard, RV (Multicolor)

4 Pack 10FT String Light Poles, Metal Light Poles for Outside String Lights,with Fork,Hanging Light Poles for Patio,Backyard,Garden,Deck,Party,Wedding

LEGO Botanicals Tiny Plants - Artificial, Fake Indoor Plant Building Set for Home, Kitchen, Desk Decoration, Adults Ages 18+ - Gift for Graduation - 10329

LEGO LEGO Botanicals Happy Plants Building Toy for Kids, Girls, and Boys 9+ - Playroom Decor for Desk or Shelf - Birthday Gift Idea for Young Gardeners - Artificial Indoor Plants for Play & Display - 10349




















