Dom manipulation inside JavaScript

Source: Internet
Author: User

1. Selection of DOM elements

<! DOCTYPE html>

Summed up mainly these several

Run effect

The above are all direct lookups, the following are indirect lookups

ParentNode          //parent node childnodes//          All child nodes FirstChild          //first child node LastChild           //Last child node nextsibling         // Next sibling node previoussibling     //Previous sibling node these are parentelement           //parent node tag elements that contain text children//                all child tags firstelementchild       //First child tag element lastelementchild        //Last child tag element nextelementtsibling     //Next sibling tag element previouselementsibling  //Previous sibling tag element

Loop the element below the parent label

<! DOCTYPE html>

2. Dom Content operation

Get label content

obj = document.getElementsByTagName (' a ') [0];//goes to the document looking for all a tags, returns a list of alert (obj.innertext);//Gets text information//alert ( obj.innerhtml);//Get inside the whole paragraph of HTML, including text

Value can be used to get the values in the form

<! DOCTYPE html>

Execution results

You can also assign values directly,

You can also manipulate styles directly

Dom manipulation inside JavaScript

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.