jquery - how to make columns except first in each row to be align left? -


I want to create all the columns except the first row in the table text-align: left , first Column text-aligned is defined in css . Here's the code:

  & lt; Script type = "text / javascript" src = "../ss / jquery-1.9.1.min.js" & gt; & Lt; / Script & gt; & Lt; Style type = "text / css" & gt; Table {boundary: 1px solid red; Degradation: collapse; } Table TD {boundary: 1 px solid red; Text align: center; } & Lt; / Style & gt; & Lt; Script type = "text / javascript" & gt; $ (Function () {$ ("input [type = 'button']"). ("Click", function () {$ ("# table tr td: gt (0)") .css ({" Text-to-curry "});});}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input type = "button" value = "click" /> & Lt; Table id = "table" & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; TD width = "150px" & gt; Center & lt; / TD & gt; & Lt; TD width = "150" & gt; Left & lt; / TD & gt; & Lt; TD width = "150" & gt; Left & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Center & lt; / TD & gt; & Lt; TD & gt; Left & lt; / TD & gt; & Lt; TD & gt; Left & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Center & lt; / TD & gt; & Lt; TD & gt; Left & lt; / TD & gt; & Lt; TD & gt; Left & lt; / TD & gt; & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / Body & gt;   

After clicking on the button, only the first row gets the effect, all the columns in the other rows are all text-left , which includes the first column is not . So why? Should I want to repeat elements with TR each method?

"itemprop =" text ">

Your current jQuery code will receive all TD and then into the archive First of all ... you get the code of TD then you get the first in that archive ... that's what happened in you current code ...

this. ..

  $ (function () is in place of your code with $ ("input" [type = 'button'] "). (" Click ", function ( } {$ ("# Table tr td") No. (': first-child'). CSS ({"text-align": "left"});});});   

More people Da is better if you can just use css ....

  table td {border: 1px solid red; text align: left;} table td: first-child {text- Align: center;}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -