Dom is the most important part of client-side JavaScript. Includes the following pieces of content:
- The node type of the DOM
- Object properties for Dom
- DOM node operations: Add, delete, change, check
- DOM Events
DOM node type:
- Document: Document itself.
- Elements: Tags. such as <body></body>, <p></p>
- Properties: Properties in the tag. such as <form method= "" action= "" > method, Action
- Text: Text in a page. such as text in <p>text</p>
- Note:/* Zhushi */.
Object Properties/Methods for common DOM
- Getattribute/setattribute can set the properties of Dom objects and support IE 8+ Browser. The value of the property can also be obtained through dom.attributes.nodeValue, and the compatibility is unknown
- Hasattribute ("attr") to determine if a attr attribute exists
- RemoveAttribute ()/Removeattributenode (attrnode) deletes the specified attribute. Removeattributnode returns the deleted attribute node.
- HasAttributes () to determine if a property exists
- ID current Node ID
- ClassName Current Node class
- Clientwidth/clientheight viewable area width/height
Additions and deletions to check:
- ParentNode can get parent node
- Firstchild/lastchild/childnodes can get child nodes, ChildNodes get nodelist.
- Nextsibling/previoussibling Get Next/previous sibling node
- AppendChild (DOM object)
- CloneNode (deep)//Deep:true/false. Determine if deep cloning
- RemoveChild ()
- ReplaceChild ()
- Ele.getelementbyid ("id")
- Ele.getelementsbytagname ("TagName")
- Ele.getelementsbyname ("name")
- Ele.getelementsbyclassname ("ClassName")//ie9+
- Ele.queryselect ("CSS selector")//ie8+
- Ele.queryselectall ("CSS selector")
Tips
Event:
1. DOM Level 0 Events (Dom.onclick) can only be bound once, and DOM Level 2 events (AddEventListener) may be bound more than once
2. When the same type of event is bound more than once, AddEventListener is executed in the order of addition. Attachevent in reverse order of addition
3. In Addeventlistner, the event object has the following properties, methods
- Target
- Type
- Stoppropagation ()
- Preventdefault ()
4. In Attachevent, the event object has the following properties, methods
- Srcelement
- Type
- Cancelbubble (default = False, set to True to cancel bubbling)
- ReturnValue (default = True, set to False to block default behavior)
Event handlers for browser
var eventutil = { addhandler:function (element, type, handler) { if (element.addeventlistener) { Element.addeventlistener (type, handler, false) } else if (element.attachevent) { element.attachevent (' on ' + Type, handler) } else { element[' on ' + type] = Handler } }, removehandler:function (element, type, Handler) { if (element.removeeventlistener) { Element.removeeventlistener (type, handler, false) } else if (element.detachevent) { element.detachevent (' on ' + type, hander) } else { element[' on ' + type] = Nu ll }} }
JavaScript DOM Related summary