Latest web development tutorials

XML DOM getElementsByTagName () method

Document Object Reference Document Object

Definition and Usage

getElementsByTagName () method returns a NodeList of all elements with the specified name.

grammar

getElementsByTagName(name)

参数 描述
name 字符串,规定要搜索的标签名。值 "*" 匹配所有的标签。


Examples

The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and displays the first value <title> element:

Examples

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName("title")[0]
y=x.childNodes[0];
document.write(y.nodeValue);

Output:

Everyday Italian

try it"

Document Object Reference Document Object