The first few chapters introduce the basics of JavaScript, the declaration of variables, the functions, and the objects that are the focus, of course, no difficulty.
Chapter three begins with the emphasis, and the DOM.
D: Documentation
O: Object-oriented
M: Model (tree)
Get element:
There are three DOM methods that can get element nodes, respectively, by element ID, by tag name, and by class name.
1.getElementById
Returns an identifier based on the ID
2.getElementByTagName
Returns an array of objects, based on the label name. Each object corresponds to a list item element in the Document object, respectively.
3.getElementByClassName
The above three methods are used to get the element, and after we get the element, we also need to get its various properties. The GetAttribute method is used to get the property, and the SetAttribute method is used to change the property.
GetAttribute is a function that has only one parameter and you intend to query the name of the property.
Object.getattribute (attribute)
The GetAttribute method is not part of the document object, so it cannot be called through the Document object. It can only be called through element nodes. For example, it can be combined with the Getelementbytag method. Gets the title property of each <p> element, as follows:
var paras = document.getelementsbytagname ("P"); for (var i = 0; i < paras.length;i++) { alert (Paras[i].getattribute ("title"));}
"JavaScript DOM programming Art" notes