document
document
The document object represents the current page. Since HTML is represented as a tree structure in the form of DOM in the browser, the document object is the root node of the entire DOM tree.
The title attribute of document is read from
Please observe the change of the browser window title.
To find a node in the DOM tree, you need to start searching from the document object. The most commonly used searches are based on ID and Tag Name.
We first prepare the HTML data:
Use getElementById() and getElementsByTagName() provided by the document object to obtain a DOM node by ID and a group of DOM nodes by Tag name:
'use strict'; var menu = document.getElementById('drink-menu'); var drinks = document.getElementsByTagName('dt'); var i, s, menu, drinks; menu = document.getElementById('drink-menu'); menu.tagName; // 'DL' drinks = document.getElementsByTagName('dt'); s = '提供的饮料有:'; for (i=0; iMocha
Hot Mocha Coffee
Yoghurt
##Beijing Old yogurt
Juice
Freshly squeezed apple juice