I'm trying to change the value of the first cell on the last row of a table.
My code is:
$(document).ready(function() {
$('table.class tr:last td:first').html('Value');
});
But that code changes nothing, but if I put without the :last and :first he fills the all table with 'Value'. What am I doing wrong?
Edit: My bad, the code works fine, but just for the last table with class 'class'.What I need it's to do that on every tables with that class. Any idea?
Use find() method to find the all table rows of the table. Use last() method to get the last row of table.
In order to use jQuery in the HTML file, we will add the below syntax inside the <head> tag. Syntax for selecting odd rows: $("table tr:odd").
Click in a cell above or below where you want to add a row. Under Table Tools, on the Layout tab, do one of the following: To add a row above the cell, click Insert Above in the Rows and Columns group. To add a row below the cell, click Insert Below in the Rows and Columns group.
For your edit, use :last-child
and :first-child
instead so it applies to the last td
in the last tr
of every table.class
:
$(document).ready(function() {
$('table.class tr:last-child td:first-child').html('Value');
});
The code works fine.
See http://jsfiddle.net/ThiefMaster/sJGZj/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With