javascript event

Total Post:2

Points:14
 517  View(s)
Ratings:
Rate this:

what is event handling  and event bubbling?

  1. Post:140

    Points:984
    Re: javascript event

    When JS called by HTML index. Javascript can "react" on these events.Often, when events happen, according to your choice of events. JavaScript lets you execute code when events are detected. 

    code content of its own element(using this.outerHTML): 

    <button onclick="this.outerHTML = Date()">The time is?</button>
    

    Javascript is several long type of text code. It is more common to see event attributes by calling thefunctions:

    <button onclick="displayDate()">The time is?</button> 

    for more info go on HTML DOM Events. 

    Event handling :-

    only assigned function is work for event handler, that function is run when that event occurs otherwise not.

    document.onclick = clickHandler; 

    Type of event handler:

    1-Interactive event handlers

    2-Non-Interactive event handlers

    Event Bubbling :-

    When an event happens on an element, it first runs for handelers,  on its parent, then all the way up on other ancestors.

    <style>
      body * {
        margin: 20px;
        border: 3px your color;
      }
    </style>
    <form onclick="alert('form')">FORM
      <div onclick="alert('div')">DIV
        <p onclick="alert('p')">P</p>
      </div>
    </form>
    

    in the above code we got three layer boxes most outer box is Form, after that DIV and most deeply nested is P.

    Happy Coding :)


      Modified On Jun-06-2018 04:52:54 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!