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>   
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.