Last active
August 11, 2018 03:11
-
-
Save ano/943b2280826ff64c78bb092e0e168ea6 to your computer and use it in GitHub Desktop.
Compares two tables and highlights the changes. The two tables MUST have two columns; the first column is for the name, and the second column is for the value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Demo: https://codepen.io/anonga/full/XBOpJq | |
| * Example Usage: | |
| #html | |
| <table id="left">...</table> | |
| <table id="right">...</table> | |
| #js | |
| compare_tables("#left","#right"); | |
| */ | |
| function compare_tables(left_table,right_table,color){ | |
| var color = (color) ? color : "red"; | |
| var rows = $(left_table + ' tr').length; | |
| for (i = 0; i < rows; i++) { | |
| var left = left_table + ' tr:nth-child('+ i +') td'; | |
| var right = right_table + ' tr:nth-child('+ i +') td'; | |
| console.log($(left).text()); | |
| console.log($(right).text()); | |
| console.log($(left).text() == $(right).text()); | |
| if($(left).text() == '' || $(right).text() == '') | |
| $(left + ':last').css('background-color', "#FF5500"); | |
| else if($(left).text() !== $(right).text()) | |
| $(left + ':last').css('background-color', color); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment