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'); 开发者_StackOverflow社区
});
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?
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/
Tested your code and it works for me. Though I would change it to this:
<script type="text/javascript">
$(document).ready(function () {
$('table#myTable tr:last td:first').html('Value');
});
</script>
Identifying the particular table you want to change. table.class will effect every table on the page.
精彩评论