3

Want to know if applied css on an element e.g. width is a pixel unit or related to viewport because window.getComputedStyle always give value in pixels.

Even tried this to identify percentage, but does not work in case of identified 'em', 'vw', 'rem' units.

Note: Not asking for inline styling on element.

Akansh
  • 1,715
  • 3
  • 15
  • 34
  • really interesting question. i hope someone will find a way to do it – taha Jul 06 '17 at 11:44
  • Why do you want to know? –  Jul 06 '17 at 12:18
  • @torazaburo want to change property value keeping the unit same. Thing is, I want to do different operations according to different property unit. – Akansh Jul 06 '17 at 12:34
  • Please give a specific example. What kind of "different operations"? –  Jul 06 '17 at 16:09
  • @torazaburo want to automate increase of width of any element without breaking responsiveness using javascript. – Akansh Jul 07 '17 at 08:11
  • We really need a more specific example of what you want to do. Under what circumstances do you want to increase the width, in a way that is expressed how, and how would this differ depending on the units in which the width was originally specified? Do you want to increase it by a particular number of pixels, or a particular percentage? –  Jul 07 '17 at 08:53

1 Answers1

-1

Maybe you can try to simulate a resize event (changing the window.innerWidth) and check if you get the same result from window.getComputedStyle

Simulate event resize

taha
  • 997
  • 9
  • 17
  • this won't work for sure. May be some combination of operations might work. Resizing is possible for popup windows, main window can not be resized by any js method. – Akansh Jul 07 '17 at 09:47