ArticleslgStudy

computer science

DOM event

DOM event is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand DOM event rather than just read about it. In short: 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.

Key takeaways

  • DOM event belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect DOM event to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of DOM event from memory before moving on to harder problems.

Reference excerpt

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.

Events

HTML events

Common events There is a huge collection of events that can be generated by most element nodes:

Mouse events. Keyboard events. HTML frame/object events. HTML form events. User interface events. Mutation events (notification of any changes to the structure of a document). Progress events (used by XMLHttpRequest and File API). Note that the event classification above is not exactly the same as W3C's classification.

Note that the events whose names start with "DOM" are currently not well supported, and for this and other performance reasons are deprecated by the W3C in DOM Level 3. Mozilla and Opera support DOMAttrModified, DOMNodeInserted, DOMNodeRemoved and DOMCharacterDataModified. Chrome and Safari support these events, except for DOMAttrModified.

Touch events Web browsers running on touch-enabled devices, such as Apple's iOS and Google's Android, generate additional events.

In the W3C draft recommendation, a TouchEvent delivers a TouchList of Touch locations, the modifier keys that were active, a TouchList of Touch locations within the targeted DOM element, and a TouchList of Touch locations that have changed since the previous TouchEvent. Apple didn't join this working group, and delayed W3C recommendation of its Touch Events Specification by disclosing patents late in the recommendation process.

Pointer events Web browsers on devices with various types of input devices including mouse, touch panel, and pen may generate integrated input events. Users can see what type of input device is pressed, what button is pressed on that device, and how strongly the button is pressed when it comes to a stylus pen. As of October 2013, this event is only supported by Internet Explorer 10 and 11.

Indie UI events Not yet really implemented, the Indie UI working groups want to help web application developers to be able to support standard user interaction events without having to handle different platform specific technical events that could match with it. Scripting usable interfaces can be difficult, especially when one considers that user interface design patterns differ across software platforms, hardware, and locales, and that those interactions can be further customized based on personal preference. Individuals are accustomed to the way the interface works on their own system, and their preferred interface frequently differs from that of the web application author's preferred interface. For example, web application authors, wishing to intercept a user's intent to undo the last action, need to "listen" for all the following events:

Control+Z on Windows and Linux. Command+Z on Mac OS X. Shake events on some mobile devices. It would be simpler to listen for a single, normalized request to "undo" the previous action.

Internet Explorer-specific events In addition to the common (W3C) events, two major types of events are added by Internet Explorer. Some of the events have been implemented as de facto standards by other browsers.

Clipboard events. Data binding events.

Note that Mozilla, Safari and Opera also support the readystatechange event for the XMLHttpRequest object. Mozilla also supports the beforeunload event using the traditional event registration method (DOM Level 0). Mozilla and Safari also support contextmenu, but Internet Explorer for Mac does not. Note that Firefox 6 and later support the beforeprint and afterprint events.

XUL events In addition to the common (W3C) events, Mozilla defined a set of events that work only with XUL elements.

Other events For Mozilla and Opera 9, there are also undocumented events known as DOMContentLoaded and DOMFrameContentLoaded which fire when the DOM content is loaded. These are different from "load" as they fire before the loading of related files (e.g., images). However, DOMContentLoaded has been added to the HTML 5 specification. The DOMContentLoaded event was also implemented in the Webkit rendering engine build 500+. This correlates to all versions of Google Chrome and Safari 3.1+. DOMContentLoaded is also implemented in Internet Explorer 9. Opera 9 also supports the Web Forms 2.0 events DOMControlValueChanged, invalid, forminput and formchange.

Event flow Consider the situation when two event targets participate in a tree. Both have event listeners registered on the same event type, say "click". When the user clicks on the inner element, there are two possible ways to handle it:

Trigger the elements from outer to inner (event capturing). This model is implemented in Netscape Navigator. Trigger the elements from inner to outer (event bubbling). This model is implemented in Internet Explorer and other browsers. W3C takes a middle position in this struggle. According to the W3C, events go through three phases when an event target participates in a tree:

The capture phase: the event travels down from the root event target to the target of an event The target phase: the event travels through the event target 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

Stopping events While an event is travelling through event listeners, the event can be stopped with event.stopPropagation() or event.stopImmediatePropagation()

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with DOM event

Start with the simplest possible case. Write down what DOM event claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to DOM event before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about DOM event ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of DOM event

In research
DOM event appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses DOM event in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
DOM event is common in secondary-school and first-year university syllabi. It links to neighbouring topics Application programming interfaces, Events (computing), World Wide Web Consortium standards, so understanding it makes those chapters shorter.
In everyday life
Look for DOM event outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “DOM event” →

How to study DOM event in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what DOM event means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain DOM event out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is DOM event in simple terms?

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 nod…

Why does DOM event matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study DOM event?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on DOM event.

Tags

  • Application programming interfaces
  • Events (computing)
  • World Wide Web Consortium standards

Keep exploring