Search code examples
jquerycssviewport-units

jQuery/JS – Get font-size in unit set in CSS (vw units)


I've set my font sizes using vw but want to retrieve this value in jQuery but when I use $('.textarea').css('font-size'); it returns the px equivalent rather than the vw unit.

Is there any way for it to return the correct stated value?


Solution

  • Once you have value in px, multiply it by 100/($(window).width())

    For example(in your case):

    $('.textarea').css('font-size')*(100/($(window).width()))
    

    Please let me know, if it works