Skip to content

Instantly share code, notes, and snippets.

@gmetais
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmetais/9fbce1cc39e5e4a7f992 to your computer and use it in GitHub Desktop.
Save gmetais/9fbce1cc39e5e4a7f992 to your computer and use it in GitHub Desktop.
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