Examples of how the document node objects are obtained

Source: Internet
Author: User
Tags tag name

  If you want to manipulate an element, first get it, here is a description of the next document node object access, interested friends do not miss

The code is as follows: <html>  <head>  <title></title>  <script>   /*  Acquisition of document node objects:    */ //First, get   function Documentdemo () {  var tablenode by ID document.getElementById ("tab_id");  TableNode.style.border = "5px solid #00ff00"; } //second, through the Name property   function DocumentDemo2 () {  var inputnode = document.getelementsbyname ("TXT");  alert ( inputnode.length);  alert (inputnode[0].value);   } //third, through tag name   function DocumentDemo3 () {   var tdnode = document.getElementsByTagName ("TD");  alert (tdnode.length);  for (var x = 0; x < TDNODE.L ength;x++) {  alert (tdnode[x].innertext); } }  </script>    <style type= "text /css ">  .onediv{  width:200px;  height:100px;  border:1px solid #f00;  margin-top:20px;  }    Table,td{  border:1px solid #00f;  width:200px;  Margin-top:20px;  text-align:center; }  </style>    </head>    <body >  <input type= "button" value= "Document object Demo" onclick= "DocumentDemo3 ()" ><br/>  <div class = "Onediv" >  This is the content of the Div   </div>    <input type= "txt" name= "txt" >  <input type = "txt" name= "txt" >      <table cellspacing= "0" id= "tab_id" >  <tr>  <td> java</td>  <td>php</td>  </tr>  <tr>  <td>.net</td>   <td>ios</td>  </tr>  </table>    <span> This is a span area </span > <br/>  <a href= "#" > This is a hyperlink </a>  <body>    </html>   

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.