Created
May 15, 2021 13:35
-
-
Save tobiasroeder/ce07cbc069d48ae313d93528fbd153ba to your computer and use it in GitHub Desktop.
Check if an element contains a specific css property.
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
// returns a boolean if the element contains that property | |
const hasCssProperty = (elmt, property) => { | |
const elmtPropertyValue = window.getComputedStyle(elmt, null).getPropertyValue(property); | |
return elmtPropertyValue ? true : false; | |
} | |
// live example | |
const elmt = document.querySelector('#video'); | |
if (hasCssProperty(elmt, 'aspect-ratio')) { | |
console.log('This browser supports aspect-ratio!'); | |
} else { | |
console.log('This browser does not support aspect-ratio!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment