1. JavaScript method: document. getElementById ("id"). innerHTML;
(1) instance description
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> obtain the subitem in HTML </title>
<Script type = "text/javascript">
Function getStr ()
{
Var str = document. getElementById ("div_child"). innerHTML;
Alert (str );
}
</Script>
</Head>
<Body>
<Div id = "div_child">
<Table>
<Tr>
<Th> </th>
<Th> </th>
<Th> </th>
<Th> </th>
<Th> </th>
</Tr>
<Tr>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
</Tr>
</Table>
<Input type = "button" id = "btn" onclick = "getStr ()" value = "get string"/>
</Div>
</Body>
</Html>
(2) click the button to bring up information
2. Method in jQuery: $ ("# id" ).html ()
(1) instance description
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> get the child node string from the parent node of jQuery </title>
<Script type = "text/javascript" src = "jquery-2.1.0.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("# Btn"). click (function (){
Var str = $ ("# div_child" 2.16.html ();
Alert (str );
});
});
</Script>
</Head>
<Body>
<Div id = "div_child">
<Table>
<Tr>
<Th> </th>
<Th> </th>
<Th> </th>
<Th> </th>
<Th> </th>
</Tr>
<Tr>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
</Tr>
<Tr>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
</Tr>
<Tr>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
</Tr>
</Table>
<Input type = "button" id = "btn" value = "get value"/>
</Div>
</Body>
</Html>
(2) running result