2017-3-31 js on element Properties. Operation of the content. Timer. The level of the element, the parent, and the subset relationship.

Source: Internet
Author: User

JS action on element content:

1. Operation Style (style)

2. Operation Properties (Attribute)

3. Operation Contents (Innerhtml/text)

One. Manipulating element properties

Common Properties: Class. Id. Style Disabled

Custom properties: You can customize an arbitrary property name, and you can place the value arbitrarily, without any effect on the element itself.

This: Represents the nearest method.

Set a property: A.setattribute ("Property name", "property value"); "When the property name does not exist, create this property and assign a value. When the property name exists, the value of the property is overwritten. 】

Gets the value of the property: A.getattribute ("property name"); "can get the value of a custom property"

Remove an attribute: A.removeattribute ("attribute name");

Two. Manipulating element content

1. Gets the contents of the form class element "[Form form] basic 12 form class elements." Details: http://www.cnblogs.com/kissdodog/archive/2013/01/10/2854917.html "

Method of Value: a.value= "";

2. Get the content of non-form class elements "div/span, etc."

Method of Value:

(1) a.innertext= "";

When adding content: "When there is a tag inside the element, the tag is executed, but the tag is not displayed"

A.innerhtml= "AAA<BR/>AAA"

Flags are executed <br/> a newline is generated, but not a realistic tag.

When getting content: "When a tag exists inside the element, the markup and the string contents are displayed together"

<div id= "a";><span>aaaa</span><div>

Gets the element with ID:<span>aaa<span> as the content

(2) a.innerhtml= "";

Add content: "Gets the text content inside the element only, the markup is displayed, but does not execute"

A.innerhtml= "AAA<BR/>AAA"

Added after: aaa<br/>aaa

Get content: "Show only string content, no markup"

<div id= "a";><span>aaaa</span><div>

Gets the content of the element with ID A: AAA

3. Common applications

(1) Create a <div class= "H1" ></div>

"1" a.innerhtml ("<div class=" H1 "></div>");

[This method produces an overlay effect when used, and ' + = ' is used when creating multiple]

"2" var a=document.createelement ("div");

A.setattribute ("Class", "H1");

(2) Automatic line-wrapping:;

Three. Timer

(1) Timers that can only be executed once

Window.settimeout (function () {}, execution countdown); "1000 milliseconds = 1 seconds"

(2) A timer that will not be terminated

Window.setinterval (function () {}, interval milliseconds); "1000 milliseconds = 1 seconds"

Termination method:

var a=window.setinterval (function () {}, time interval milliseconds);

Window.clearinterval (a);

Four. Level, child, parent relationship

"Level, child space and newline count a location"

Parent of element A: A.parentnode

The previous element in the peer of element A: A.previoussibling and the previous a.previoussibling.previoussibling

The next element in the middle of element a: a.nextsibling another a.nextsibling.nextsibling

Child of Element A:

Nth sub-level a.childnodes[n]

First sub-a.firstchild

Last sub-a.lastchild

2017-3-31 js on element Properties. Operation of the content. Timer. The level of the element, the parent, and the subset relationship.

Related Article

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.