Skip to content

Instantly share code, notes, and snippets.

@parrfolio
Created January 6, 2011 00:27
Show Gist options
  • Save parrfolio/767298 to your computer and use it in GitHub Desktop.
Save parrfolio/767298 to your computer and use it in GitHub Desktop.
jQuery Table Column Highlight
// highlight columns by Christopher Clark
$("tbody").delegate("td", "mouseover mouseout", function (e) {
if (e.type == 'mouseover') {
// multiple class attr value support - the column identifier is always the first class value
var target = $(this).attr("class");
if (target) {
target = target.split(" ").slice(0, 1).toString();
$("col." + target).addClass("highlight");
}
} else if (e.type == 'mouseout') {
$("col").removeClass("highlight");
}
});
@clarkus
Copy link

clarkus commented Apr 6, 2011

Updated version to use indexes. This pattern is from our locked column pattern.

        // highlight columns        
            $("tbody").delegate("td", "mouseover mouseout", function (e) {
                var parentTable = $(this).parents("table");
                if (e.type == 'mouseover') {
                    // multiple class attr value support - the column identifier is always the first class value
                    var target = $(this).index() + 1;
                    if (target) {
                        $("col:nth-child(" + target + ")", parentTable).addClass("highlight");
                    }
                } else if (e.type == 'mouseout') {
                    $("col.highlight").removeClass("highlight");
                }
            });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment