Trying to get div dimensions in vh / vw instead of pixels

I am trying to have mutable divs in my application. For this, I need to save the changes specified by the user in my database.

My question is, how do I change the units given to me from px to something else? When I do this:

console.log(event.target.style.width)

      

it shows the width in px

. Is there a way to get it, say, %

or vh

/ vw

?

+3


source to share


1 answer


What about:

event.target.style.width / document.documentElement.clientWidth * 100

      



Divide the pixel width by the total viewport width, then multiply by 100 to get the percentage.

+1


source







All Articles