Four elephant zhenfa: Add delete Change find "in order to facilitate memory, reduce the use of brain memory, I named JS Heart for: Tao Zhenfa, two instruments ZHENFA, three just ZHENFA, four like Zhenfa, five lines zhenfa, just remember ZHENFA keyword, you can search the brain of the corresponding content, learn JS five Zhenfa can learn JS"
Dom operation additions and deletions (Document Object model)
Add nodes:
var div=document.createelement ("div");
var text=document.createtextnode ("I am a text node");
Fathernode.appchild (Childnode); "Add Childnode inside Fathernode element"
Fathernode.insertbefore (Insertnode,targetnode); "Add Childnode inside Fathernode element"
Node.clonenode (ture); "True to replicate node nodes and their child nodes, false to copy only node nodes, false when not filled, false when an IMG tag is copied"
To delete a node:
Fathernode.removechild (Childnode); "Delete Fathernode element internal node Childnode"
To change the node:
Fathernode.replacechild (Replacenode,targetnode); "If ReplaceNode is an existing node, the target will be deleted and the ReplaceNode placed here"
Find:
var Idselector=document.getelementbyid ("#selector");
var tagselector=document.getelementsbytagname ("div");
var tagselector=idselector.getelementsbytagname ("div"); "Select only Idselector div"
H5 element Selector
var classselector=document.getelementsbyclassname (". Selector") "Support ie9+"
var query=document.queryselector ("#selector") "support all selectors in CS" "Support ie8+" "returns the first matching element"
var queryall=document.queryselectorall (". Selector") "support all selectors in CS" "Support ie8+" "Returns all matching node list NodeList class array"
"Classlist Series ie9+ Support"
Classlist.add ("Class1,class2 ...") "Add one or more class names"
Classlist.remove ("Class1,class2 ...") "Delete one or more class names"
Classlist.toggel ("class") "Toggle class name"
Classlist.contains ("class") "Determines whether the class name exists, exists not true, does not exist as false"
Claslist.item (Index) "Returns the class name for the specified index"
Classlist.length "Returns the number of class names"
JS Learning Road Series Summary of the four image array (this article is like martial arts in the Easy Rib, is you gallop it field of martial arts heart, learn JS five big Zhenfa learned JS, Bo Master proposed to learn three before the first array)