javascript - How can I get all <tr>-s from a <tbody> and convert it to String? -


i have html table:

<table id="persons" border="1">     <thead id="theadid">         <tr>             <th>name</th>             <th>sex</th>             <th>message</th>         </tr>     </thead>     <tbody id="tbodyid">         <tr>             <td>viktor</td>             <td>male</td>             <td>etc</td>         </tr>         <tr>             <td>melissa</td>             <td>female</td>             <td>etc</td>         </tr>         <tr>             <td>joe</td>             <td>male</td>             <td>etc</td>         </tr>     </tbody> </table> <input type="button" onclick="gettbodystring();" value="get it"/> 

i want jquery/javascript, can inside of tbody string. like:

function gettbodystring() {     var tbodystring = $(.......).text(); //or val()?     alert("the body - "+tbodystring); } 

the result in alert window should this:

the body - <tr><td>viktor</td><td>male</td><td>etc</td></tr><tr><td>melissa</td><td>female</td><td>etc</td></tr><tr><td>joe</td><td>male</td><td>etc</td></tr> 

could me?

you need html() instead of text(). function text not return tags returns plain text within tags.

var tbodystring = $('#tbodyid').html();  

i use native javascript function here faster jquery.

var tbodystring = document.getelementbyid('tbodyid').innerhtml;  

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -