Created
July 6, 2020 14:15
-
-
Save mantismamita/ac1cf44faeabfd02262de85c190403db to your computer and use it in GitHub Desktop.
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
const getStyle = (classOrId, property) => { | |
var firstChar = classOrId.charAt(0); | |
var remaining= classOrId.substring(1); | |
var elem = (firstChar =='#') ? document.getElementById(remaining) : document.getElementsByClassName(remaining)[0]; | |
if(elem) { | |
return window.getComputedStyle(elem).getPropertyValue(property); | |
} | |
return; | |
} | |
//usage | |
let containerWidth= getStyle('.container', 'width'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment