First, he thought row
(1) concept: kill all, leaving their
(2) Usage : first to traverse the collection of elements, and then put all the elements set the style is empty, then the current set of elements highlighted .
(3) Code:
Second, the operation of custom properties
(1) for custom attributes: element .getAttribute (property name);
(2) to set custom properties: element .setAttribute (attribute name, attribute value);
(3) remove custom attributes: element .removeAttribute (property name);
(4) H5 operating custom properties: It is recommended custom attributes begin with the date in the H5; help us to carry out the acquisition element .dataset property name;.
Third, the node operation
1, access node
(1) obtain parent and child nodes:
Get the parent node : element parentNode;.
Gets the child element : element children;.
Getting child nodes: element childNodes;.
Get the first child node | element: element firstchild; | element firstElementchild;.
Gets the last child | child elements: element lastchild; | element lastElementchild;..
(2) obtaining siblings
Gets the previous sibling | element: element previousSibling; | element previousElementSibling;..
Gets the next sibling | element: element nextSibling; | element .nextElementSibling;..
Code:
2, node dynamically add
(1)element . innerHTML =" " ;
(2 ) create elements and then add:
Creating elements : var li = document createElement ( ' li') // just in memory;.
. Mounted to the DOM tree: parent appendChild (li) adding sub-elements; | parent insertBefore (li, reference elements);.
DOM tree: