Niranjan Godbole Niranjan Godbole - 1 year ago 93
jQuery Question

How to get text of TD in jquery on dynamically generated table in mvc4?

Hi I have one dynamically generated table. Below is the structure of dynamically generated table. I want to get value of TD which will be having class="user".

@foreach (var group in Model.detailsbyclientId)
<tr class="rowid">
<td> @group.clientName </td>
<td> @group.employeeId </td>
<td> @group.employeeName </td>
<td> @group.Nationality</td>
<td> @group.documentType </td>
<td scope="col">
<input type="button" class="btn btn-primary btn-cons" value="View Document" onclick="showDocumentData('@group.upld_Id');"/>
<td id="Hi">@group.currentStatus</td>
<td class="user"><input type="hidden" id="Status" value="@group.currentStatus"/></td>

I am trying to get value of each TD as below.

$(".rowid").each(function() {
var a = $(this).find(".user").text();

However I am getting blank in alert on each iteration. So can anyone suggest me where i am wrong in above line of code? Thank you

Answer Source

try this

$(".rowid").each(function() {
        var a = $(this).find(".user").html();

if you are looking for value of input then

        $(".rowid").each(function () {
            var a = $(this).find(".user input").val();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download