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