-
Notifications
You must be signed in to change notification settings - Fork 1
05. DOM and Events
idavidov13 edited this page Jan 26, 2024
·
5 revisions
Browser Object Model (BOM) - Browsers expose some objects like window, screen, navigator, history, location, document, …

The DOM represents the document as nodes and objects. That way, the programming languages can connect to the page.
- HTML elements as objects
- Properties
- Methods
- Events
The elements are nested in each other and create a hierarchy, like the hierarchy of a street address – Country, City, Street, etc.
DOCUMENT OBJECT MODEL: structured representation of HTML documents. Allows JS to access HTML elements and styles to manipulate them.

- Check the contents and structure of elements on the page
- Modify element style and properties
- Read user input and react to events
- Create and remove elements
- Events are "fired" when something of interest happens
- Directly in the developer console – when debugging
- As a page event handler – e.g., the user clicks on a button
- Via inline script, using <script> tags
- By importing from an external file – the most flexible method
- They can be accessed and modified like regular objects
- Select an element to obtain a reference
- Modify its properties
- Attributes initialize DOM properties
- Property values can change via the DOM API
- innerHTML
- textContent
- value
- style
- By ID - getElementById()
- By class name - getElementsByClassName()
- By tag name - getElementsByTagName()
- By CSS selector - querySelector(), querySelectorAll()
These methods return a reference to the element, which can be manipulated with JavaScript