Skip to content

Instantly share code, notes, and snippets.

@stefaneg
Created October 2, 2013 11:56
Show Gist options
  • Save stefaneg/6792580 to your computer and use it in GitHub Desktop.
Save stefaneg/6792580 to your computer and use it in GitHub Desktop.
AngularJS add class to table header on cell hover. Add this directive to td being rendered in order to get class set on the corresponding td in thead section of the table.
.directive('addClassToHeaderOnHover', function(){
return function(scope, element, attrs){
var classname = element.attr('add-class-to-header-on-hover');
element.mouseenter(function(){
var idx = element.index() + 1;
var $htd = element.parents('table').find('thead td:nth-child(' + idx + ')');
$htd.addClass(classname);
});
element.mouseleave(function(){
var $htd = element.parents('table').find('thead td');
$htd.removeClass(classname);
});
}
})
@mg1075
Copy link

mg1075 commented Mar 18, 2015

Nice.
May want to use th rather than td inside the thead.

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