Created
September 9, 2022 12:11
-
-
Save y-a-v-a/d54e57ff01205e91d3bd81dc20e59295 to your computer and use it in GitHub Desktop.
Simple feature detection for CSS :has()
This file contains hidden or 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() { | |
const s = document.createElement('style'); | |
s.textContent = `.supportsHas:has(p):after {content: "hasHas";}`; | |
document.head.appendChild(s); | |
const supportsHas = document.createElement('div'); | |
supportsHas.classList.add('supportsHas'); | |
const p = document.createElement('p'); | |
supportsHas.appendChild(p); | |
document.body.appendChild(supportsHas); | |
if (getComputedStyle(document.body, 'after')?.content === '"hasHas"') { | |
console.log('supports :has()'); | |
} else { | |
console.log('does not suport :has()'); | |
} | |
document.head.removeChild(s); | |
document.body.removeChild(supportsHas); | |
}()); |
Author
y-a-v-a
commented
Sep 12, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment