JavaScript DOM Related summary

Source: Internet
Author: User

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")


    • The name and ID of an element are best different. getElementById and Getelementsbyname access both the ID and name in some browsers.
    • queryselect/queryselectall differs from jquery selector:
      1. queryselect/queryselectall is to find all nodes that meet the current criteria and then filter on the calling element.
      2. jquery is a stepwise lookup of elements.
    • queryselectorall returns a static node list, and Getelementsby returns a Live Node list. The following demo 2 will cause an infinite loop
    • var ul = document.getElementsByTagName ("ul") [0];//demo1var list = Ul.queryselectall ("Li"); for (var i = 0; i < list.length; i++)    {var li = document.createelement ("Li"); Ul.appendchild (LI);} Demo2var list = ul.getelementsbytagname ("Li"); for (var i = 0; i < list.length; i++) {var li = Document.createeleme    NT ("Li"); Ul.appendchild (LI)} 


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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.