Ask questions and get good answers on mb.jQuery.components

How do I take the last row of a table that has an id which not ends with a specific suffix?

    <table id="table">
        <tr id="row1">
            <td>1</td>        
        </tr>
        <tr id="row2">
           <td>2</td>        
        </tr>
        <tr id="row3_DETAILS">
           <td>3</td>        
        </tr>
    </table>

I would take the last row of the table with id "table" that has that id does not end with "_DETAILS". So the row with id "row2_DATA".

asked Nov 04 '09 at 11:37

Federico%20Soldani's gravatar image

Federico Soldani
173128

edited Nov 10 '09 at 20:47

Pietro%20Polsinelli's gravatar image

Pietro Polsinelli ♦♦
407


jQuery allows selector filtering with a simple syntax (http://docs.jquery.com/Selectors); using this syntax you can get the last tr which ID doesn't ends with "_DETAILS" just in one time, without looping the DOM:

   $("#table tr:not([id$=_DETAILS]):last");

So, if you need to get the content of that ROW:

   $("#table tr:not([id$=_DETAILS]):last td").html();

which result is: 2

answered Nov 04 '09 at 13:35

Matteo%20Bicocchi's gravatar image

Matteo Bicocchi ♦♦
1776129

Your answer
toggle preview

jQuery main site - Matteo Bicocchi