Week4day2 JavaScript and the DOM
The DOM.
Just like CSS, JavaScript also is able to identify and manipulate the elements in our HTML pages by using the Document Object Model.
- The Document Object
The HTMLElement.click() method simulates a mouse click on an element.
When click() is used with supported elements (such as an <input>), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.
Syntax:
click()
// On mouse-over, execute myFunction function myFunction() { document.getElementById("myCheck").click(); }
- Selectors
Document: querySelector() method
Syntax:
querySelector(selectors) Examples:
JavaScript
const el = document.querySelector(".myclass");
Selector Description Example
("*") Selects all elements in the document
(this) Selects the current HTML element
("p.intro") Selects all
elements with class="intro" ("div p") Selects all
element inside all
("div p:first-child") Selects the first
element inside all
elements