Working with trtd to optimize JQuery

2

I want to study more about <table> <tr> <td> etc, to optimize my projects. Example: I have 4 <tr> with 2 <td> each, when applying a formula in jQuery for example, that adds the first <td> with the second <td> of each <tr> using a little formula. I want to know how to reference the first with the second of each line.
Any ideas?

    
asked by anonymous 29.10.2017 / 02:39

1 answer

2

To reference the first td of each tr , you can use two ways:

1st: with first-child :

$("tbody tr td:first-child").css("color","red");
  

:first-child is a pseudo-class , which, in this case, reference   every first% of% daughter of a td in tr .

2nd: with tbody :

$("tbody tr td:nth-child(1)").css("color","red");

To reference the second nth-child(1) of each td , you can use tr :

$("tbody tr td:nth-child(2)").css("color","red");

To reference the third nth-child(2) on, just change the index to 3, 4 onwards:

$("tbody tr td:nth-child(index)").css("color","red");
  

Remember that the index of td in jQuery starts with 1.

    
29.10.2017 / 03:08