I'm looking to retrieve the max-width
value in px
from CSS for use in a JavaScript code. The challenge is that this value might be specified in different units in the CSS file. Any suggestions on how to achieve this using JavaScript?
const element = document.querySelector("div")
const elementMaxWidth = window.getComputedStyle(element).maxWidth
console.log(elementMaxWidth)
div {max-width: 50%}
<div>Lorem, ipsum.</div>