Giter Site home page Giter Site logo

aws-javascript-events's Introduction

JavaScript Events

Learning Goals

  • Define a JavaScript event
  • Identify different types of user events

Introduction

We've experimented with selecting and manipulating nodes in the DOM using JavaScript: deleting nodes, editing nodes, etc. But most web applications are not used by people opening up the console and editing the DOM using Chrome's DevTools. Instead, people do something and then work happens.

"Doing work" in response to "something happening" is known as event handling. Events are the "something the user does" and the "callback function" is the work that will happen in response to the event being triggered.

In this lesson we'll go over some of the most commonly-used JavaScript events. In the following lessons, we'll learn how to use event listeners to tell JavaScript which event or events we want it to listen for. We'll also learn how to implement callback functions to handle the work happens part of event handling.

Define a JavaScript Event

JavaScript has the ability to "listen" for things that happen inside the browser. It can listen for events like whether the browser is resized, or whether someone clicked on a specific image on the screen. The event you're probably most familiar with is "click."

We'll go over a few of the more common types of events in this lesson.

Identify Different Types of User Events

Mouse Click

Mouse or trackpad events are some of the most common ones you'll be handling using JavaScript eventing. For example, JavaScript can recognize a single click on an element in the page and change the styling of the element to highlight it. Or it can recognize a double-click on an element and open a zoomed-in view of that element.

There are many other mouse events you can use; take a look at the list of JavaScript's mouse events here.

Key Press

While click events will likely make up the majority of events you'll use, the keyboard is another important source of events. JavaScript currently includes two keyboard events: keydown and keyup. (A third, keypress, has been deprecated.) When a key is pressed, these events provide a code to indicate which key it was. For example, a game program might listen for keydown events and, if the space bar was pressed, make the character jump over the hole.

Form Submission

HTML pages often use a submit button to submit a form to a server. When a user submits a form, the submit event is fired. An event handler here might pop up a thank you overlay or log in the user and take them to their home page.

Other Events

As you seek to build more complicated applications, you'll need to handle and trigger work on many more events than the few we've discussed in this lesson. Some other common events you are likely to encounter are scroll, mouseenter and mouseleave, focus, blur, and onchange.

One important thing to keep in mind is that not all JavaScript events are supported by all browsers. This list of browser events includes the ones that can be used in most browsers.

Conclusion

JavaScript allows us to trigger work when it detects events. You set up an event handler and, when JavaScript recognizes that event, it will execute the event handler's work, which is stored in a callback function.

Take a few minutes to look through the list of common events to familiarize yourself with the many many ways you can use event handling to enhance your users' experience.

Resources

aws-javascript-events's People

Contributors

jlboba avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.