JQuery uses the text () or HTML () function to get the contents of the TD:
$ ("TD"). Text (); or $ ("TD"). HTML ();
The difference is that the former returns the text content of the selected element, which returns the contents of the selected element (including HTML tags).
The following example shows the contents of TD cells for all selected rows after clicking the button
1. HTML structure
<table id = "TEST" >
<tr><td><input type= "checkbox" name= "Test" ></td><td>1</td></tr>
<tr><td><input type= "checkbox" name= "Test" ></td><td>4</td></tr>
<tr><td><input type= "checkbox" name= "Test" ></td><td>7</td></tr>
<tr><td><input type= "checkbox" name= "Test" ></td><td>10</td></tr>
</table>
<input type= "button" value= "OK" >
2. jquery Code
$ (function () {
$ (": Button"). Click (function () {
str = $ (": checkbox:checked"). Map (function () {
return $ (this). Parent (). Siblings (' TD '). text (); Locate the following TD according to the checkbox, and then use the text () function to get the content
}). Get (). Join (","); Get an array of content and stitch it into a string
alert (str); Output
});
});
3. Effect Demonstration
How to use jquery to get the content inside TD