Skip to content

Instantly share code, notes, and snippets.

@collin
Created October 28, 2008 23:09
Show Gist options
  • Save collin/20545 to your computer and use it in GitHub Desktop.
Save collin/20545 to your computer and use it in GitHub Desktop.
// When hovering over an anchor
// find all anchors with the same href attribute
// and give them all a 'hover' class
;(function(_){
jQuery.fn.extend({
attrSelector: function(attr) {
return '['
+ attr
+ '="'
+ this.attr(attr)
+ '"]';
},
matchingAttribute: function(attr) {
return $(this.attrSelector(attr));
}
});
_(function() {
_('a').hover(
function(){
_(this).matchingAttribute('href').addClass('hover');
}
,function() {
_(this).matchingAttribute('href').removeClass('hover');
}
);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment