How can I determine if an element has it's CSS width/height set to 'auto' or '100%' using vanilla JS and cross-browser solution?
Using the style property, only returns in-line styles that are set.
document.querySelector("#foo").style.height
Returns: ""
Using getComputedStyle gives a unit value.
getComputedStyle(document.querySelector("#foo")).height
Returns: "334.641px"
The result I am seeking would return what value is set on the element
Return "auto"
or
Return "80%"
There's an old post from 2011 about walking the stylesheets, but browsers have evolved significantly since then. Surely there must currently be a better way?
For example, Chrome's Computed Property inspector will list style property underneath the computed px value (there's a little drop down arrow if the property was set via CSS). It accomplishes this via computedStyleMap() in the following answer, but not all browsers implement it.
width: 385px;
100%. .w-full tailwinds.css:6366