Nitesh
Nitesh

Reputation: 575

How to get inner tr tag using JQuery?

I am trying to grab documentnumber attribute from the tr tags inside tbody, and save it in an array.

Below is the html , I am working on

<tbody class="line-item-grid-body">
    <tr data-group-sequence-number-field-index="" data-sequence-number-field-index="1" documentnumber="80" documentid="4133604" parent="80" class="line-item parent-line-item line-item-show reorderable-row  droppable-element">
        <td> 
                 <table>
                   <tbody>
            <tr></tr>
                   </tbody>
                 </table>
        </td>
   </tr>
    <tr data-group-sequence-number-field-index="" data-sequence-number-field-index="1" documentnumber="80" documentid="4133604" parent="80" class="line-item parent-line-item line-item-show reorderable-row  droppable-element">
   </tr>
</tbody>

and this is what I did, which is not working. If I don't specify particular class then system also grabs inner tr tags, which I don't want

var docs = jQuery("#line-item-grid").find('tbody').find("tr[class='line-item parent-line-item line-item-show reorderable-row  droppable-element']");

for (i=1;i<=docs.length;i++)
{
var tempValue = jQuery(docs[i]).attr('documentnumber');
alert(tempValue);
}

Any ideas?

Upvotes: 1

Views: 3571

Answers (3)

inbit
inbit

Reputation: 21

Hmm i didn't test this (so check for typos), but off top of my head, i'd try something like this:

jQuery(".line-item-grid tbody > tr").each(function() {
  alert($(this).attr('documentnumber');
});

You can define selectors one after another, pretty much same as in CSS. Also check child selector (http://api.jquery.com/child-selector/) for selecting direct child elements.

Hope it helps

Upvotes: 0

damon
damon

Reputation: 1085

There's several ways you could go about this. I would do the following....

var docs = $('.line-item-grid-body>tr');

Docpage: Child selector

Another option:

var docs = $('.line-item-grid-body').children('tr');

Bookmark and frequent this page ... Selectors - jQuery API

Upvotes: 3

TommyBs
TommyBs

Reputation: 9646

try this as your selector

  $('tbody > tr','#line-item-grid');

Upvotes: 2

Related Questions