Quick and silly jQuery selector question.
Why this does not work: jsFiddle demo
//config
var ThisTable = $('.ReallyLongSillyTableName');
// Function
$(ThisTable + ' > tbody > tr > td:last-child').each(function() {
$(this).append('Sales Orders: ');
});
But, this does work: jsFiddle demo
$('.ReallyLongSillyTableName td:last-child').each(function() {
$(this).append('Some Text');
});
Any suggestions much appreciated.
You can use either this:
$('tbody > tr > td:last-child', ThisTable).each(function() {
$(this).append('Sales Orders: ');
});
or this:
ThisTable.find('tbody > tr > td:last-child').each(function() {
$(this).append('Sales Orders: ');
});
Try like below,
ThisTable.find('tbody > tr > td:last-child').each(function() {
$(this).append('Sales Orders: ');
});
$('.ReallyLongSillyTableName');
is a jQuery object, so you can't use it as String.
So try
var ThisTable = '.ReallyLongSillyTableName';
// Function
$(ThisTable + ' > tbody > tr > td:last-child').each(function() {
$(this).append('Sales Orders: ');
});
$(ThisTable + ' td:last-child').each(function() {
$(this).append('Some Text');
});
and you can use ThisTable
as above or $(ThisTable)
(to make it jquery object) for other purpose.