Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector with variable in the selector

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.

like image 579
Iladarsda Avatar asked Feb 11 '26 13:02

Iladarsda


1 Answers

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: ');
});
like image 139
VisioN Avatar answered Feb 13 '26 12:02

VisioN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!