0

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>
        <td id="Hi">@group.currentStatus</td>
        <td class="user"><input type="hidden" id="Status" value="@group.currentStatus"/></td>
        <td></td>
    </tr>

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

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

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

2
  • 1
    1. Ids have to be unique (<td id="Hi">, <input id="Status">) 2. There's no text in td.user. Are you looking for the value of the hidden <input />? Commented Sep 26, 2016 at 12:19
  • var a = $(this).find(".user").children('input').val(); Commented Sep 26, 2016 at 12:20

3 Answers 3

3

You should get the value of input inside .user like following.

$(".rowid").each(function() {
    var a = $(this).find(".user input").val();
    alert(a);
});
Sign up to request clarification or add additional context in comments.

Comments

0

try this

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

if you are looking for value of input then

        $(".rowid").each(function () {
            var a = $(this).find(".user input").val();
            alert(a);
        });

1 Comment

Worked out. Great. Thanks a lot
0

$(()=>{
  
   $.each($('.user'),(i,d)=>{
    
       alert($(d).html());
   
  });
  
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
      
      <tr>
          <td> 1 </td>
           <td class='user'> google </td>   
      </tr>
      <tr>
            <td> 2 </td>
           <td class='user'> fb </td>
        </tr>
        <tr>
            <td> 3 </td>
           <td class='user'> youtube </td>
        </tr>
   </table>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.