javascript - What is an efficient way to set CSS class for each cell in a given table row? -


I have a problem in setting a CSS class for each cell in a table table initially I thought the original line css set Will affect the style properties of cells, but that does not work; Instead, I need to loop through all the cells in a row to update the CSS class.

Although it is not efficient and it took a lot of time. Consider my situation: I have approximately 230 lines, with 23 cells (fully 5280 cells) in each row.

Note: If I do not use any framework, can you suggest an approach in native JS?

Update:

Its work is fine by using Paolo's recommendation ..

Initially my custom CSS class Has been done by way

  .grid_RowItalicsBold {PADDING-RIGHT: 5px; Padding-left: 8 pixels; font-weight: bold; Font-size: 8pt; Hidden flurry; Art color; Line-HEIGHT: 15pt; Font-style: normal; Fun-family: Wardana, Ariel, Saines-Serif; White-space: Abrop; Background-color: yellow; Text-decoration: none}  

and I made it

  tr.Grid_RowItalicsBold TD {PADDING-RIGHT: 5px; Padding-left: 8 pixels; font-weight: bold; Font-size: 8pt; Hidden flurry; Art color; Line-HEIGHT: 15pt; Font-style: normal; Fun-family: Wardana, Ariel, Saines-Serif; White-space: Abrop; Background-color: yellow; Text-decoration: none}  

And I assigned this class to my special lines using JavaScript. :)

Why can not you set the square of the line and adjust your CSS accordingly?

  & lt; Tr class = "myclass" & gt; & Lt; TD & gt; ... & lt; / TD & gt; & Lt; TD & gt; ... & lt; / TD & gt; & Lt; / TR & gt;  

Then in the CSS:

  tr.myclass td {...}  

In either case, Suppose in the table is an id of "mytable", you can give all the table rows you want to the table:

  var rows = document.getElementById ('mytable'). GetElementsByTagName ('tr'); (Var x = 0; x & lt; rows.length; x ++) {rows [x] .className = rows [x] .className + "myclass"; }  

If you are doing this in the entire table, however, you can give only one category yourself in the table table:

  table.micrash Tr TD {...}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -