GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

DOM event

DOM (Document Object Model) Events are a signal that something has occurred, or is occurring, and can be triggered by user interactions or by the browser. Client-side scripting languages like JavaScript, JScript, VBScript, and Java can register various event handlers or listeners on the element nodes inside a DOM tree, such as in HTML, XHTML, XUL, and SVG documents. Examples of DOM Events: * When a user clicks the mouse * When a web page has loaded * When an image has been loaded * When the mouse moves over an element * When an input field is changed * When an HTML form is submitted * When a user presses a key Historically, like DOM, the event models used by various web browsers had some... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

DOM (Document Object Model) Events are a signal that something has occurred, or is occurring, and can be triggered by user interactions or by the browser. Client-side scripting languages like JavaScript, JScript, VBScript, and Java can register various event handlers or listeners on the element nodes inside a DOM tree, such as in HTML, XHTML, XUL, and SVG documents. Examples of DOM Events: When a user clicks the mouse When a web page has loaded When an image has been loaded When the mouse moves over an element When an input field is changed When an HTML form is submitted When a user presses a key Historically, like DOM, the event models used by various web browsers had some significant differences which caused compatibility problems. To combat this, the event model was standardized by the World Wide Web Consortium (W3C) in DOM Level 2. The bubble phase (optional): the event travels back up from the target of an event to the root event target. The bubble phase will only occur for events that bubble (where event.bubbles == true ) You can find a visualization of this event flow at https://domevents.dev Inline Event Handling Inline Event Handling Hey Joe ! function triggerAlert(name) { window.alert("Hey " + name); } One common misconception with the inline model is the belief that it allows the registration of event handlers with custom arguments, e.g. name in the triggerAlert function. While it may seem like that is the case in the example above, what is really happening is that the JavaScript engine of the browser creates an anonymous function containing the statements in the onclick attribute. The onclick handler of the element would be bound to the following anonymous function: function () { triggerAlert('Joe'); return false; } This limitation of the JavaScript event model is usually overcome by assigning attributes to the function object of the event handler or by using closures. Traditional Event Handling Traditional Event Handling Hey Joe! var triggerAlert = function () { window.alert("Hey Joe"); }; // Assign an event handler document.onclick = triggerAlert; // Assign another event handler window.onload = triggerAlert; // Remove the event handler that was just assigned window.onload = null; To add parameters: var name = 'Joe'; document.onclick = (function (name) { return function () { alert('Hey ' + name + '!'); }; }(name)); Inner functions preserve their scope. DOM Level 2 DOM Level 2 Hey Joe! var heyJoe = function () { window.alert("Hey Joe!"); } // Add an event handler document.addEventListener( "click", heyJoe, true ); // capture phase // Add another event handler window.addEventListener( "load", heyJoe, false ); // bubbling phase // Remove the event handler just added window.removeEventListener( "load", heyJoe, false ); Internet Explorer-specific model Internet Explorer-specific model Hey Joe! var heyJoe = function () { window.alert("Hey Joe!"); } // Add an event handler document.attachEvent("onclick", heyJoe); // Add another event handler window.attachEvent("onload", heyJoe); // Remove the event handler just added window.detachEvent("onload", heyJoe);

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"DOM event". 1735905634. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1267067316

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·