How to use jquery to get the content inside TD

Source: Internet
Author: User

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

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.