Saturday, 15 August 2015

jquery - Append <th> Class to <td> in the Same Column -


I am now searching all over the net on the net, but I still can not figure it out.

  & lt; Table & gt; & Lt; TR & gt; & Lt; Th class = "name" & gt; Name & lt; / Th & gt; & Lt; Th class = "age" & gt; Age & lt; / Th & gt; & Lt; Th class = "nick" & gt; Nick & lt; / Th & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; John & lt; / TD & gt; & Lt; TD & gt; 30 & lt; / TD & gt; & Lt; TD & gt; Johnny & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Robert & lt; / TD & gt; & Lt; TD & gt; 35 & lt; / TD & gt; & Lt; TD & gt; Bob & lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt;  

Is there any way to tag classes with those headers to tag TD in the same column?

"itemprop =" text ">

I will do it like this:

  $ ("Table th") each (function (i, val) {var var = $ (this); var selector = "td: nth-child" (+ + (i + 1 + +)); th.parent () . Sister (). (Selector) Search .attr ("class", th.attr ("orbit");});  

This is effectively the same & lt; Td> is used to get

Note: You must add an index to the index because the index is every () on

is null-based but : nth-child () is one-based.

In addition to this, you can not select the : eq reference as it matches only one element.


No comments:

Post a Comment