Last active
August 29, 2015 14:15
-
-
Save gmetais/9fbce1cc39e5e4a7f992 to your computer and use it in GitHub Desktop.
Find a CSS property in the page
This file contains hidden or 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
/** | |
* 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