aldimeola1122
aldimeola1122

Reputation: 818

jQuery Table call td value only text

I have a table (id="deneme").

I need to iterate through the td value, determine which checkboxes the user has checked, and for the rows with a checked checkbox, grab the value for the only text(literal) of middle column.

Maybe for first letter can be defined an algorithm.

<table id="docsTable">
    <tr bgcolor="#E7DDCC" class="liste-0">
        <td align="center"><input type="checkbox"/></td>
        <td>Document Title 1</td>
        <td>567</td>
    </tr>
    <tr bgcolor="#E7DDCC">
        <td align="center"><input type="checkbox"/></td>
        <td>accure</td>
        <td>134</td>
    </tr>
    <tr bgcolor="#E7DDCC">
        <td align="center"><input type="checkbox"/></td>
        <td>Zebra</td>
        <td>231</td>
    </tr>
</table>
<input type='button' id='btnTest' value='Get Rows' />

$(function() {
    $('#btnTest').click(function() {
        $('#docsTable input[type="checkbox"]:checked').each(function() {
            var $row = $(this).parents('tr');
            alert($row.find('td:eq(0) input').val());
            alert($row.find('td:eq(1)').html());
            alert($row.find('td:eq(2)').html());
        });
    });
});

Demo :

http://www.jsfiddle.net/3yYFY/

How can i do that?

Thanks in advance.

Upvotes: 0

Views: 2652

Answers (4)

Ruslanas Balčiūnas
Ruslanas Balčiūnas

Reputation: 7418

$(':checked')​.parent().next().each(function(){alert($(this).html())})

Upvotes: 0

Tomalak
Tomalak

Reputation: 338178

$("#docsTable input:checked").closest("tr").find("td:eq(1)").map(function () {
  return $(this).text();
}).toArray()

Upvotes: 0

Ram
Ram

Reputation: 144689

You can use has and map methods and store the values an in array.

$('#btnTest').click(function() {
    var arr = $('#docsTable tr').has('input[type="checkbox"]:checked').map(function() {
        return $('td:eq(1)', this).text()
    }).get();
});

http://jsfiddle.net/twn2W/

Upvotes: 1

Jigar Jain
Jigar Jain

Reputation: 1447

By what i have understood from your question, you should use closest() instead of find() method

Upvotes: 0

Related Questions