Home > Web Front-end > JS Tutorial > body text

A brief discussion on DOM methods in javascript_javascript skills

WBOY
Release: 2016-05-16 15:50:03
Original
1166 people have browsed it

1: Three ways to obtain objects

1) document.getElementById(id); Get it through the object’s attribute id;

2) element.getElementByTagName(tag); Get by tag name;

3) element.getElementByClassName(class); Get it through the attribute class name;

2: Set and get methods of attributes.

1) object.getAttribute(attribute); Get the attribute of the element.===>>>HTMLDOM: object.attribute;

 2)object.setAttribute(attribute,value);Set the attribute of the element.====>>>HTMLDOM:object.attribute=value;

3: Some properties of nodes

1) childNodes attribute: returns an array.

 element.childNodes[0] is equivalent to element.firstChild

 element.childNodes[element.childNodes.length] is equivalent to element.lastChild

2) nodeType attribute: There are 12 possible values ​​in total. But only 3 of them are valuable

nodeType=1 of element node

 Attribute node nodeType=2

Text node nodeType=3

 3) nodeValue attribute: The main function is to change the text content in the element. The function is similar to object.innerHTML

For example:

This is a text node

var p=document.getElementById("p");

p.childNodes[0].nodeValue="Change the content of the text node";

This changes the content in the p node;

It can also be implemented like this: p.innerHTML="Change the content of the text node";

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template