Created
January 28, 2017 13:13
-
-
Save LiuuY/12c83beb817ebbfa8e381a2a897739cb to your computer and use it in GitHub Desktop.
How to get the background color of an element using javascript
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 getBgColor(e, pseudo) { | |
var transparent = 'rgba(0, 0, 0, 0)' | |
if (!e) { | |
return transparent | |
} | |
var currentBgColor = window.getComputedStyle(e, pseudo).backgroundColor | |
if (currentBgColor === transparent) { | |
getBgColor(e.parentElement) | |
} | |
return currentBgColor | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment