Merging Unmergin Table Cells

Merging Unmergin Table Cells

Hi Guys,
Here is the issue I'm currently having.
I have a HTML table with five columns and 50 rows. some of the cells in the columns have repeated text that I would like to have the option to merge or unmerge. Here is my merge function
  1. function mergeGridCells()
  2. {
  3. var dimension_col = null;
  4.  
  5. dimension_col = 1;
  6. // first_instance holds the first instance of identical td
  7. var first_instance = null;
  8. var rowspan=1;
  9. var columnCount = $("#mainTable tr:first th").length;
  10. for (dimension_col = 1; dimension_col <= columnCount; dimension_col++) {
  11. var first_instance = null;
  12. var rowspan = 1;
  13. $("#mainTable").find('tr:visible').each(function() {
  14. var dimension_td = $(this).find('td:nth-child(' + dimension_col + '):visible');
  15. if (first_instance == null) {
  16. // must be the first row
  17. first_instance = dimension_td;
  18. } else if (dimension_td.text() == first_instance.text()) {
  19. // the current td is identical to the previous
  20. // remove the current td
  21. //var myBg = dimension_td.css('background-color');
  22. dimension_td.hide();
  23. ++rowspan;
  24. // increment the rowspan attribute of the first instance
  25. first_instance.attr('rowspan', rowspan);
  26. first_instance.css('vertical-align', 'middle');
  27. first_instance.css('background-color', '#FFFFFF');
  28. } else {
  29. // this cell is different from the last
  30. first_instance = dimension_td;
  31. rowspan=1;
  32. }
  33. });
  34. }
This function works great in all browser (Chrome, IE/EDGE, Firefox, Opera) the problem is when I try to unmerge the cells once they have been merge. Here is the function I'm currently using to unmerge the cells.

  1. function unmergeCells() {
  2. $temp = $("#mainTable td[rowspan]");
  3. $temp.each(function() {
  4. $(this).attr("rowspan", "0");
  5. });
  6. $("#mainTable td:hidden").show();
  7. $("#mainTable td").css("background-color","");
  8. $("#mainTable tr:not(:has(th))").css("background-color","#FFFFFF");
  9. $("#mainTable tr:not(:has(th)):odd").css("background-color","#D4D4D4");
  10. }
this function works well with Chrome and Opera but not in Firefox/Edge. Is there a way I can improve the code to make it work in firefox/Edge?
Any help will be greatly appreciated.