You are viewing limited content. For full access, please sign in.

Question

Question

Dynamically change color of table rows

asked on May 22, 2015 • Show version history

Our tables in the forms are difficult to read the data.  So, is it possible to assign a color to all Odd numbered rows for example?  The rows are dynamically added by the users who fill the form.

 

Thanks

0 0

Answer

APPROVED ANSWER
replied on May 22, 2015

You can use some Javascript like this

$(document).ready(function() {
  
  altColor();

  $('.rowcolortable').on('click', '.form-del-field', function () {
    altColor();
  });
  
  $('.rowcolortable').on('click', '.cf-table-add-row', function () {
    altColor();
  });
  
  function altColor() {
    $("tr:odd").css("background-color", "#ff0000");
    $("tr:even").css("background-color", "#ffffff");
  }
});

Note that the table would be using the CSS class rowcolortable. It takes into account a table where you allow the user to add or delete rows to it so it doesn't have to be a fixed table.

5 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.