Client programming-JavaScript (3)

Source: Internet
Author: User
Tags html comment
What is an object model?
An object model is an interface used to describe the logical structure of an object and its standard operation methods. It consists of four main parts: 1. javascript language Core 2. the core objects related to data types. browser object 4. document Object

Four obvious object models
1. Traditional JavaScript Object Model
2. Extended JavaScript Object Model
3. DHTML-style Object Model
4. Extended ferry object model and standard DOM

Common Document objects
Lastmodified location referrer (link URL)

Access document elements
1. Access document. Forms [0] Through location
2. Use Id or name document. myform or document. Forms [myform]

Three levels of DOM
Dom0: supports common object model set forms [] images [] Anchors [] link [] applets []
Dom1: provides the ability to manipulate all elements in a document through a set of common function sets
Dom2: provides more access to the main XML-related page elements while adding support for style sheet access and manipulation.

DOM nodes and HTML documents
1 element XHTML Element
2 attribute attributes
3 Text Content
8 comment comments
9 document root Document Object
10 documenttype Document Type Definition

Dom node attributes
Nodename node name
The value of the nodevalue node is generally applicable to text nodes.
For the nodetype node type, see the preceding

Access Element
1. Access document. getelementbyid ("ID") by ID ")
2. Use the name attribute of the element document. getelementsbyname ("name ")
3. Access the element getelementsbytagname ('P ')

Determine whether the node haschildnodes () exists ()

Common Document Tree navigation start point
Document.doc umentelement points to the HTML-relative root element of the Document Tree <HTML>
Document. Body points to the Tree node corresponding to the <body> flag
Document.doc type points to the doctype definition of the document, but this attribute cannot be changed.

Create a node
Creatattribute (name) creates a specified attribute for the element
Createcomment (string) creates an HTML comment
Createdocumentfragment () creates an element. The element type is specified in the tagname parameter.
Createtextnode (string) creates a text node containing strings

Add or insert nodes
Appendchild (New subnode)
Insertbefore (New subnode, refer to subnode)

Delete or replace a node
Current. removechiled (current. lastchild)
ReplaceChild (newchild, oldchild)

Modify the value of a text node
Textnode. Data = "new text"

Operation attribute
Getattribute () setattribute () removeattribute () determines whether an element defines hasattributes ()

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.