Skip to main content

JS Concepts : Events










There are 3 ways to assign event handlers:
  1. HTML attribute: onclick="...".
  2. DOM property: elem.onclick = function.
  3. Methods: elem.addEventListener(event, handler[, phase]) to add, removeEventListener to remove.
-
-


Types of Events


1.  Form element events:
  • submit – when the visitor submits a 
    .
  • focus – when the visitor focuses on an element, e.g. on an 



2.  Mouse events:
  • click – when the mouse clicks on an element (touchscreen devices generate it on a tap).
  • contextmenu – when the mouse right-clicks on an element.
  • mouseover / mouseout – when the mouse cursor comes over / leaves an element.
  • mousedown / mouseup – when the mouse button is pressed / released over an element.
  • mousemove – when the mouse is moved.

3.Keyboard events:
  • keydown and keyup – when the visitor presses and then releases the button.
4. Document events
  • DOMContentLoaded – when the HTML is loaded and processed, DOM is fully built.


    5.  CSS events:
    • transitionend – when a CSS-animation finishes.


    Mouse events:
    There are many other events. We’ll get into more details of particular events in next chapters.

    All mouse events include the information about pressed modifier keys.
    The properties are:
    • shiftKey
    • altKey
    • ctrlKey
    • metaKey (Cmd for Mac)
    For instance, the button below only works on Alt+Shift+click:

     btn.onclick = function(event) {
       if (event.altKey & amp; & amp; event.shiftKey) {
         alert('Hooray!');
       }
     };


    Comments

    Popular posts from this blog

    Microservices Design patterns

    What are microservices? Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are Highly maintainable and testable Loosely coupled Independently deployable Organized around business capabilities Owned by a small team The microservice architecture enables the rapid, frequent and reliable delivery of large, complex applications. It also enables an organization to evolve its technology stack. You are developing a server-side enterprise application. It must support a variety of different clients including desktop browsers, mobile browsers and native mobile applications. The application might also expose an API for 3rd parties to consume. It might also integrate with other applications via either web services or a message broker. The application handles requests (HTTP requests and messages) by executing business logic; accessing a database; exchanging messages with other systems; and returni...

    GraphQL

    What is GraphQL  API Standard invented & open-sourced by Facebook Alternative to  REST API  enables declarative data fetching  exposes single endpoint & responds to queries How it works?  Why Graphql? Improvises performance by reducing the data that is to be transferred over the internet Variety of different frontend frameworks and platforms on client-side Fast development speed & expectation for rapid feature development Why Graphql is better than REST? Flexibility & efficient  No more over /under fetching of data Over fetching : Under fetching: Insightful analytics  Schema serves as contract between client and server CORE CONCEPTS : SDL :SCHEMA DEFINITION LANGUAGE Writing Data with mutations 3 kinds of mutations creating new data updating existing data deleting existing data