A simple example of the contents of TR and TD in the Table node in JS _jquery

Source: Internet
Author: User
<table id= "tb1" width= "border=" 1 "cellpadding=" 4 "cellspacing=" 0 ">
    <tr> <td height=
        " 25 " > First line </td>
    </tr>
    <tr>
        <td height= "A" > second line </td>
    </tr> <tr>
        <td height= > Third line </td>
    </tr>
    <tr>
        <td height= ">" Line four </td>
    </tr>
		 <tr>
        <td height= "><input type=" button "Name=" Gettablecontent "value=" Get Table Contents "onclick=" gettablecontent (this) ></td>
    </tr>
</table >

As shown in the Code, the button clicks the event to pass in the This object, which is the button itself. Test the data that gets the table in the following ways

<script language= The parent node
    of the parent node of the JavaScript > Function gettablecontent (node) {
//button is tr.
		  var tr1 = Node.parentNode.parentNode;
			alert (tr1.rowindex);
			alert (Tr1.cells[0].childnodes[0].value); Method of obtaining one
alert (tr1.cells[0].innertext); 
Find the Table object in the following ways, getting tr,td. Then get TD's HTML content
        var table = document.getElementById ("tb1");//Get first table
		
        var child = Table.getelementsbytagname (" TR ") [rowindex-1];//gets the first cell of the row
				
        var text = Child.firstChild.innerHTML;
        Window.alert ("form" + RowIndex + "content is:" + text);
    }
</script>

The above is small series for everyone to get the table node of the TR and TD content simple examples of all the content, I hope we support cloud Habitat Community ~

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.