Javascript operations on dom -- get the sibling node & getElementsByTagName usage

Source: Internet
Author: User
[Html]... & lt; tr & gt; & lt; tdname & amp; #39; subbtn & amp; #39; id & amp; #39; subbtn & amp; #39; & gt; afdfa & lt;/td & gt; & lt; td & gt; adda & lt;/td & gt; & lt; td & gt; 3dd & lt; /td & gt; & lt;/tr & gt;

[Html]
....
AfdfaAdda3dd 
DdbbBddd5dd 
CcddFdd5d55 
....
Script
Var sub = document. getElementById ("subbtn ");
Var thb = document. getElementById ("thid ");
Var ths = document. getElementsByTagName ("th ");
Var value = ths [0]. innerHTML;
Thfirst = ths [0];
Value = thfirst. nextSibling. innerHTML;
Alert (value)
Alert (sub. name)
Script

Document Tree node
ParentElement parent Element
ParentNode parent node
All child nodes of childNodes have s.
First child node of firstChild
Last child node of lastChild
Next sibling node of nextSibling
A sibling node on previussibling

You can use innerHTML to obtain the value of an element.

 

GetElementsByTagName

Var item = document. getElementById ('id'). getElementsByTagName ("tag name ");

Item [1] is the first tag (in IE, it is the second tag, and IE starts counting from 0)


Author: cjh6311882
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.