Skip to content

Instantly share code, notes, and snippets.

@gmetais gmetais/findCssProperty.js
Last active Aug 29, 2015

Embed
What would you like to do?
Find a CSS property in the page
/**
* Copy this function in the browser console then start using.
*
* Examples:
*
* findCssProperty('background-image')
* --> log into the console all the background-images used
*
* findCssProperty('font-family', 'Roboto')
* --> log into the console all elements that have a background that contains the string "Roboto"
*
* findCssProperty('font-weight', 'bold', true)
* --> same but in strict mode, the property must exactly be 'bold'
*
*/
function findCssProperty(property, contains, strict) {
var elements = document.getElementsByTagName('*');
Array.prototype.forEach.call(elements, function(element) {
var value = window.getComputedStyle(element, null).getPropertyValue(property);
if (contains) {
if (strict) {
if (value === contains) {
console.log(element);
}
} else {
if (value.indexOf(contains) >= 0) {
console.log(element);
}
}
} else {
console.log(value);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.