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>
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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):
Javascript is several long type of text code. It is more common to see event attributes by calling thefunctions:
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.
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 :)