Created
December 5, 2023 11:45
-
-
Save esedic/810a24cc4223ad0f523d22e202d413b7 to your computer and use it in GitHub Desktop.
Extract computed background color hex value from given element object
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
var el = document.getElementById('target'); | |
function extractHexBackgroundColorFromElement(element) { | |
return getComputedStyle(element)['background-color'].split('(')[1].split(')')[0].split(',').map((x) => x.trim()).map((x) => { x = parseInt(x).toString(16); return (x.length === 1) ? '0' + x : x }).join(''); | |
} | |
console.log(extractHexBackgroundColorFromElement(el)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment