JS dom most commonly used API

Source: Internet
Author: User

Document Method:
var cont = document.getelementbyidx_x (' cont ');

ClassName Adding class to tags
Cont.classname = ' Fcolor ';

The SetAttribute method can add some properties, but not CSS styles!
var a_id = document.getelementbyidx_x (' a_id ');
A_id.setattribute (' href ', ' http://www.oeeee.com ');

What is produced by getattribute
var A_att = a_id.getattribute (' href ');
document.write (' getattribute ' generated content: ' + A_att + ' <br> ' + ' <br> ');

What is produced by removeattribute
var A_att = a_id.removeattribute (' href ');
document.write (' RemoveAttribute after the content: ' + A_att + ' <br> ' + ' <br> ');

innerHTML Getting HTML content
document.write (' InnerHTML ' generated content: ' + cont.innerhtml + ' <br> ');

The Getelementsbytagname_r () method returns a collection of objects with the specified label name, not commonly used
var div = document.getelementsbytagname_r (' div ');
document.write (' Getelementbytagname () generated content: ' + div.length + ' <br> ');

Document.body returns the BODY element tag
var dom_body = document.body;
Dom_body.setattribute (' bgcolor ', ' #186376 ');


var txt = dom_body.createtextnode (' DFSDFSDJFFDSF ');
var p = dom_body.createelement_x (' P ');
P.appendchild (TXT);
Dom_body.appendchild (P);

----------------------------------------------------------------------------

    1. Document Method:
    2. getElementById (ID) node returns a reference to the specified node.
    3. Getelementsbytagname_r (name) NodeList returns a collection of all matching elements in the document
    4. createelement_x (name) node node
    5. createTextNode (text) node creates a plain text node
    6. Ownerdocument document points to the documentation that this node belongs to
    7. DocumentElement node returns HTML nodes
    8. Document.body node returns to the body nodes
    9. Element method:
    10. GetAttribute (AttributeName) String returns the value of the specified property
    11. SetAttribute (Attributename,value) String assigns a value to a property
    12. RemoveAttribute (attributename) String removes the specified property and its value
    13. Getelementsbytagname_r (name) NodeList returns a collection of all matching elements within a node
    14. Node Method:
    15. AppendChild (Child) node adds a new sub-node to the specified node.
    16. RemoveChild (Child) node removes sub-nodes of the specified node
    17. ReplaceChild (newchild,oldchild) node replaces the child nodes of the specified node
    18. InsertBefore (newchild,refchild) node inserts a new node in front of the node at the same level
    19. HasChildNodes () Boolean returns True if the node has a child node.
    20. Node Property:
    21. NodeName string holds the name of the node in the form of a string
    22. NodeType String type of node to be stored in integer data format
    23. NodeValue String holds the value of the node in the available format
    24. ParentNode node's reference to the parent node of the node point
    25. ChildNodes NodeList A collection of references that point to a child node
    26. FirstChild node refers to the first sub-node in the binding of a child node
    27. LastChild node refers to the last sub-node in the Union of child nodes
    28. PreviousSibling node points to the previous sibling; If the node is a sibling node, the value is null
    29. NextSibling node points to the latter sibling, and if the node is a sibling node, the value is null

JS dom most commonly used API

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.