With the HTML DOM, JavaScript can access and change all the elements of an HTML document.
With the object model, JavaScript gets all the power it needs to create dynamic HTML:
The HTML DOM document object is the owner of all other objects in your web page.
The document object represents your web page.
If you want to access any element in an HTML page, you always start with accessing the document object.
Method | Description |
---|---|
document.getElementById(id) | Find an element by element id |
document.getElementsByTagName(name) | Find elements by tag name |
document.getElementsByClassName(name) | Find elements by class name |
document.querySelector(selectors); | Returns the first element within the document using CSS like selector |
document.querySelectorAll(selectors); | Returns a list of the elements within the document using CSS like selector |
Method | Description |
---|---|
element.innerHTML = new html content | Change the inner HTML of an element |
element.setAttribute (attribute, value) | Change the attribute value of an HTML element |
element.style. property = new style | Change the style of an HTML element |
Method | Description |
---|---|
document.createElement(element) | Create an HTML element |
document.removeChild(element) | Remove an HTML element |
document.appendChild(element) | Add an HTML element |
document.replaceChild(newChild, oldChild) | Replace an HTML element |
document.write(text) | Write into the HTML output stream |
Method | Description |
---|---|
document.getElementById(id).onclick = function(){code} | Adding event handler code to an onclick event |
document.getElementById(id).addEventListener('click', handler) | Adding event listener |
document.getElementById(id).removeEventListener('click', handler) | Removing event listener by the reference |
The Browser Object Model (BOM) allows JavaScript to "talk to" the browser.
https://learn.javascript.ru/document Документ и объекты страницы
Use only JavaScript for layout and adding styles
Create such article block
The layout is changing according to window size
Create Dropdown top menu
Hover
Click
Hover menu item
Use only JavaScript events