JavaScript Dom Outline

Source: Internet
Author: User
Tags tag name

Tag: Selected node content change HTML NTS delete node att before

DOM defines a standard way to access and manipulate HTML documents

Access (Find tags)
----Direct Lookup
document.getElementById ("Idname")
document.getElementsByTagName ("TagName")
Document.getelementsbyname ("name")
Document.getelementsbyclassname ("name")

----Navigation Properties
Nodeelement.parentelement//parent node Tag element
Nodeelement.children//All sub-tags
Nodeelement.firstelementchild//First child tag element
Nodeelement.lastelementchild//Last child tag element
Nodeelement.nextelementtsibling//Next sibling tag element
Nodeelement.previouselementsibling//Previous sibling tag element

Operation
1 text manipulation
Value operation
Element.innerhtml (Operations on labels)
Element.innertext (about text operations)
Assignment operation:
Element.innerhtml= ""
Element.innertext= ""



2 Property Operations <div key1=value1 key2=value2>div</div>
Attribute value: (1) Element.getattribute (attribute name).

(2) element. Attribute name (recommended)

Assignment operation: (1) Element.setattribute (property name, property value).

(2) element. Property Name = property value

About the class attribute:
Element.classlist.add ("Class value")
Element.classlist.remove ("Class value")

About the Select tag:
Ele_select.options.length=0 emptying operation
Ele_select.selectedindex index value of option selected


About the Style property: Implementing a CSS operation on a tag
Element.style. Style attribute = "value"




3 node operation

-----Add Tags
Generate a tag: var ele_create=document.createelement ("tag name")
<p></p>

Add Tags:

Parent tag. appendchild (add Tag object)
InsertBefore

-----Delete a node:

Parent tag. RemoveChild (the Label object found)

-----Replacement Node:
Parent tag. ReplaceChild (NewNode, found label object)


-----Copy a Node
Node.clonenode (true)//true means copying child nodes at the same time

Dom two types of binding event modes
Mode 1
<script>
function foo (self) {
Alert (123)
Self: <p onclick= ' foo (this) ' ></p>
}
</script>
<p onclick= "foo (this)" ></p>

Mode 2
A Label object. On Event =function () {
Alert (456)
This: The label object of the binding event
}

Specific events

Click event onclick
Get/Lose Focus onfocus onblur
Content changed onchange (selecte)
Onmouse Mouse-related events
Commit Event: onsubmit
Load event: OnLoad

JavaScript Dom Outline

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.