Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created December 12, 2014 11:39
Show Gist options
  • Save Langmans/aa406e456f914f29af56 to your computer and use it in GitHub Desktop.
Save Langmans/aa406e456f914f29af56 to your computer and use it in GitHub Desktop.
$.fn.isCSS = function (properties) {
var property;
for (property in properties) {
if (properties.hasOwnProperty(property)) {
var required_value = properties[property],
actual_value = this.css(property);
//console.log('$.isCSS', property, '=', required_value, required_value != actual_value ? '!=' : '==', actual_value, this[0]);
if (required_value != actual_value) {
return false;
}
}
}
return true;
};
$.fn.getParentsWithCSS = function (properties) {
var error;
if (this.length != 1) {
error = 'Object length (' + this.length + ') is not 1.';
throw error;
}
return this.parents().filter(function () {
return $(this).isCSS(properties);
});
};
$.fn.getParentWithCSS = function (properties) {
var error, $parent = this;
if (this.length != 1) {
error = 'Object length (' + this.length + ') is not 1.';
throw error;
}
//try {
while (($parent = $parent.parent()) && $parent[0] != document && $parent.length) {
if ($parent.isCSS(properties)) {
return $parent;
}
}
//} catch (e) {
// console.log('getParentWithCSS', e, $parent);
//}
// not found!
return $([]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment