JQuery selector for last column of first row

I am trying to change the value of the first cell in the last row of a table.

My code is:

$(document).ready(function() {
    $('table.class tr:last td:first').html('Value');     
});

But this code does not change anything, but if I put without: last and: first, it fills the whole table with value. What am I doing wrong?

Edit: my bad, the code works fine, but only for the last table with the class 'class'. What I need to do this on every table with this class. Any idea?

+5
source share
3 answers

For your editing, use :last-childand :first-childinstead, so that it applies to the last tdin the last of treach table.class:

$(document).ready(function() {
    $('table.class tr:last-child td:first-child').html('Value');
});
+9
source

, . :

<script type="text/javascript">
        $(document).ready(function () {
            $('table#myTable tr:last td:first').html('Value');
        });

    </script>

Identification of the specific table that you want to change. table.class will affect every table on the page.

0
source

All Articles