user2075124
user2075124

Reputation: 227

jquery get and append id from table

I have the following html:

<table class="userenrolment ajaxactive">
<tbody>
<tr class="userinforow r0" id="user_9">
<td class="field col_userdetails cell c0" style="">
</td>
<td class="field col_enrol cell c4 lastcol" style="">
<div class="enrolment"><span>Team 1</span>
</div>
</td>
</tr>
<tr class="userinforow r1" id="user_4">
<td class="field col_userdetails cell c0" style="">
</td>
<td class="field col_enrol cell c4 lastcol" style="">
<div class="enrolment"><span>Team 2</span>
</div>
</td>
</tr>
</tbody>
</table>

Using jQuery i want to get the id from each tr and append it to on the same row.

My function looks like this, but it doesnt work at all:

function show_groups(){
table.find('.userinforow).each(function(){
    var text = $(this).find('#id').val();
    $('.enrolment').append('text:' + text + ' <br>');
} 

Upvotes: 0

Views: 85

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

You need

function show_groups() {
    $('.userenrolment').find('.userinforow').each(function () {
        $(this).find('.enrolment').append('text:' + this.id + ' <br>');
    });
}

Demo: Fiddle

Upvotes: 1

Related Questions