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 xxx in the HTML document, but it can be changed dynamically:

   

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; i
       

Mocha

Hot Mocha Coffee

Yoghurt

##Beijing Old yogurt

Juice

Freshly squeezed apple juice

   
摩卡
热摩卡咖啡
酸奶
北京老酸奶
果汁
鲜榨苹果汁


Continuing Learning
||
摩卡
热摩卡咖啡
酸奶
北京老酸奶
果汁
鲜榨苹果汁
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!