Phillip Senn
Phillip Senn

Reputation: 47635

jQuery syntax for changing the value of a table cell

I have a table where every row has a unique id. The last table cell has class="status" where I want to show the user the result of their action.

In my $.ajax call, I have:

        ,success: function(result){
            $('tr#'+result).td('.status').text('Updated');
        };

result is the id of the row that was updated.

It's just throwing an error message that says $( and that's all.

Upvotes: 0

Views: 886

Answers (2)

user173357
user173357

Reputation:

Ancestory/descendant relationships can be put in a single $ call like this:

$('tr#' + result + ' td.status').text('Updated');

Just remember to put a space between the ancestor and child. Example output:

$('tr#row10 td.status').text('Updated');

Additionally, an ID should only be sued once, so you could probably omit the initial tr, like:

$('#' + result + ' td.status').text('Updated');

See http://api.jquery.com/descendant-selector/

Upvotes: 1

jholster
jholster

Reputation: 5136

There are no method named .td(). This is probably what you are looking for:

$('tr#' + result + ' td.status').text('Updated');

Also make sure that result has valid value.

console.log(result);

You didn't post whole code, but it looks like parse error – the code should probably end with });, not };.

Upvotes: 2

Related Questions