I"(function() { $(function() { return $("[data-select-columns]").each(function() { return $(this).on('change', function() { var headers, not_selected, selected, table, table_selector; table_selector = $(this).data('select-columns-target'); table = $(table_selector); headers = $(table_selector + " th"); selected = $(this).find(":selected"); not_selected = $(this).find(":not(:selected)"); console.log(headers); console.log(selected); console.log(not_selected); selected.each(function() { var column_index, th_id; th_id = $(this).attr('value'); column_index = $(table_selector + " tbody tr:first th").index(th_id); return $(table_selector + " td:nth-child(" + column_index + ")").show(); }); return not_selected.each(function() { var column_index, th_id; th_id = $(this).attr('value'); column_index = $(table_selector + " tbody tr:first th").index(th_id); return $(table_selector + " td:nth-child(" + column_index + ")").hide(); }); }); }); }); }).call(this); :ET