DOM - это всего лишь набор объектов и методов в них, для работы с содержимым html-страниц. Это своеобразная прослойка между JS-кодом и содержимым html-страницы
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)(getAttribute, hasAttribute) | 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 |
document.insertBefore(newEl, el); | Insert an element before second argument ekement |
childNodes | все прямые потомки узла |
---|---|
firstChild | первый прямой потомок узла |
lastChild | последний прямой потомок узла |
nextSibling | соседний узел, стоящий за текущим |
previousSibling | соседний узел, стоящий перед текущим |
nodeType | тип узла (текст, элемент, комментарий и т.д.) |
parentNode | родительский узел |
Text
◦ Window ◦ Document ◦ Screen ◦ Navigator
◦ Location ◦ History
The Browser Object Model (BOM) allows JavaScript to "talk to" the browser.
var newwin = window.open();
if (newwin.closed) {
document.getElementById("mes").innerHTML = "Окно newwin было закрыто.";
} else{
document.getElementById("mes").innerHTML = "Окно newwin открыто в данный момент.";
}
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 |
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