SoFunction
Updated on 2025-03-03

A brief discussion on the DOM method in javascript

1: Three ways to get the object

1)(id); Get it through the object's attribute id;

2)(tag); obtain through the tag name;

3)(class); Get it through the attribute class name;

2: Set and get methods of properties.

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

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

3: Some properties related to nodes

1) childNodes property: Return an array.

[0] is equivalent to

[] is equivalent to

2) nodeType attribute: There are 12 possible values. But only 3 of them have useful value.

nodeType=1 of element node

nodeType=2 of attribute node

nodeType=3 for text nodes

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

For example: <p>This is a text node</p>

var p=("p");

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

This changes the content in the p node;

It can also be implemented in this way:="change the content of the text node";

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