0

For example I have an table filled with values

-----------------------------------------
S.No   |   Name      |       Address
-----------------------------------------
       |  Dinesh     |       Salem
-----------------------------------------
       |  Senthil    |       Chennai
-----------------------------------------
       |  Sundar     |       Namakkal
-----------------------------------------

Actually I need to fill serial no to each row dynamically using jQuery.

var i = 1;
$('#tbl td').each(function() {
    $(this).append(i);
    i++;
});

I need the output should be:

-----------------------------------------
S.No    |   Name      |       Address
-----------------------------------------
   1    |  Dinesh     |       Salem
-----------------------------------------
   2    |  Senthil    |       Chennai
-----------------------------------------
   3    |  Sundar     |       Namakkal
-----------------------------------------

Please help me to solve this problem.

1 Answer 1

2

If you wanna replace first td , you can use :first-child

Try like this

var i=1;
$('#tbl td:first-child').each(function() {
    $(this).html(i);
    i++;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.