Last active
December 22, 2015 11:59
-
-
Save boblauer/6469430 to your computer and use it in GitHub Desktop.
Check if a class is affecting the style of an element.
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
(function() { | |
var affected = [], unaffected = [], | |
className; | |
className = prompt('Class to check:'); | |
if (!className) return; | |
$('.' + className).each(function() { | |
var element = this, | |
$element = $(this), | |
before = [], after = []; | |
var styleProps = Object.keys(JSON.parse(JSON.stringify(element.style))); | |
var before = [], after = []; | |
styleProps.forEach(function(style) { | |
before.push($element.css(style)); | |
}); | |
$element.removeClass(className); | |
styleProps.forEach(function(style) { | |
after.push($element.css(style)); | |
}); | |
$element.addClass(className); | |
if (before.join('') === after.join('')) { | |
unaffected.push(element); | |
} | |
else { | |
affected.push(element); | |
} | |
}); | |
console.log(affected.length + ' element(s) DO have styles applied from the ' + className + ' class.'); | |
affected.forEach(function(el) { console.log(el); }); | |
console.log(unaffected.length + ' element(s) do NOT have styles applied from the ' + className + ' class.'); | |
unaffected.forEach(function(el) { console.log(el); }); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment