Created
October 2, 2013 11:56
-
-
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.
This file contains 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
.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); | |
}); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice.
May want to use
th
rather thantd
inside thethead
.