How do alternate table row colours dynamically using css only? Else with javascript? Can i use them inside struts iterate tag?

Recommended Answers

All 3 Replies

What do you mean by dynamically alternate row colours? Are you generating the html for the rows dynamically? If so, you'll have to dynamically indicate the class of the rows too. Example, in your css:

.row1 {background-color: black};
.row2 {background-color: white};

Then in the script used to dynamically create the table, alternate between printing the row1 and row2 class:

foreach (rowelement) {
    if ($rowname = 'row1') $rowname = 'row2';
    else $rowname = 'row1';
    print "<tr class=$rowname>";
   }

The rows are added dynamically.
1. No jsp is involved.
2. Server side html is used.

The code you have written are which elements?

Just use simple JavaScrip here, it will better.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.