Pick up the mood, learn to learn js! Summarize your own study income!
There are three ways to get the nodes of an element, respectively, by the element ID, by the signature and the class name.
1.GetElmentById: Returns an object corresponding to the element node that has the value of the given ID attribute, with only one argument, and the value of the id attribute of the element must be in single or double quotes
Documrnt. Getelmentbyid (ID)
2.GetElmentsByTagName: The method returns an array of objects, each corresponding to an element in the document that has a given tag, whose argument is the name of the label
Dovument. Getelmentsbytagname (TAG)
3.GetElmentsByClassName: Returns an array of elements with the same class name, accepting only one parameter, that is, the class name
Document. Getelmentsbyclassname (Class)
Get and Set properties
1.getAttribute: is a function, he has only one parameter---intended to query the name of the property, he can only be called through the element node object, can only be used for element nodes. For example, he can be used with the Getelmentsbytagname method to get the title property of each <p> element
var paras=document. Getelmentsbytagname ("P"); for (var i=0;i<paras.length;i++) { alert (Paras[i].getattribute ("title")); }
2.setAttribute: Run changes to the value of the attribute node and can only be used for element nodes.
Object.setattribute (Attribute,value);
Here's something to note: After making changes to the document through SetAttribute, and then viewing the document source through the browser's view source option, it is still the value of the property before the change. In other words, the changes made by setattribute are not reflected in the source code of the document, which is the source of the DOM work mode, loading the static content of the document, dynamic refresh, dynamic refresh does not affect the static content of the documents, that is, the content of the page will not need to refresh the page in the browser
JavaScript Learning path elements get and set properties