views:

449

answers:

1

I am doing an MVC with C# application. I was trying to access the entire row in a table and change the values in each cell using jquery.

I need to do change the value in each td once a json call is succeeded.

Please advice for this

+3  A: 

Let's say 'ID' of your table is 'myTable'.

$.getJSON('http://yourpageurl.com',
    function(data)
    {
     //Let's say you want to modify all the cells in the first row.
     $('#myTable tr:first td')
      .each(
       function()
       {
        //'this' represens the cell in the first row.
        $(this).html('changing cell value');
       }
      );

     //If you want to access all cells of all the rows, replace
     //#myTable tr:first td with
     //'#myTable td'    


    }
);

EDIT:

If you know 'id' for your tr, you can replace

'#myTable tr:first td' selector with '#<>' replace <> with your TR id.

SolutionYogi
the tr in my table will have dynamic values for its id. IN that case, how to access. The Json call will be in a javascript function whick looks like below:function SubmitReport(id) {//json goes here}
Prasad
$(this).html('changing cell value'); should be replaced with $(this).children('td').html('changing cell value'); otherwise you will replace the whole td element with new value and as far as I understand you want to replace only the contents of td.
RaYell
RaYell, thanks for pointing out the mistake. I corrected the selector.
SolutionYogi
Prasad, if your TR's have dynamic ids and you know them, you can use them to access the cells in the particular row.
SolutionYogi