Search code examples
javascripthtmlcssmeasurement

rem px in Javascript


I use this code in JS:

bigPhoto.setAttribute("width", "200rem");

The result is in pixel in html source,

enter image description here

But:

enter image description here

When I change it to 20rem the photo become really small.

I couldn't solve the problem which is mentioned in the photos.


Solution

  • The HTML width attribute only takes an integer number of pixels or a percentage (followed by a % sign).

    If you wish to use CSS length units you have to use CSS (and set bigPhoto.style.width = "200rem".