Skip to content

Instantly share code, notes, and snippets.

@tobiasroeder
Created May 15, 2021 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasroeder/ce07cbc069d48ae313d93528fbd153ba to your computer and use it in GitHub Desktop.
Save tobiasroeder/ce07cbc069d48ae313d93528fbd153ba to your computer and use it in GitHub Desktop.
Check if an element contains a specific css property.
// 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