Created
July 24, 2012 11:58
-
-
Save lifo101/3169552 to your computer and use it in GitHub Desktop.
jquery plugin to find the closest CSS style of a DOM element's parents.
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
// $().closestStyle() | |
// find the closest CSS style of a parent for a DOM element and apply it | |
// to the selected element. I use this mainly before calling | |
// .effect('highlight') so the backgroundColor will mesh properly. | |
// @example: | |
// $('.row').closestStyle('backgroundColor').effect('highlight'); | |
(function($){ | |
$.fn.closestStyle = function(attr, val){ | |
var me = $(this); | |
me.parents().each(function(i){ | |
var c = $(this).css(attr); | |
if (c != 'transparent') { | |
me.css(attr, c); | |
return false; // stop | |
} | |
return true; // strict compliance | |
}); | |
return this; | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment