javascript event

what is event handling  and event bubbling?

Last updated:6/6/2018 1:41:10 AM

1 Answers

Prakash nidhi Verma
Prakash nidhi Verma

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.

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

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 :)