How to get height in percentage instead of in pixels from inline style?

css, html, javascript, jquery

Solution

You can use:

$('.wrapper > div').each(function () {
    var height = this.style.height;
    console.log(height); 
});

Updated Fiddle

Problem

So basically, I have many elements with an inline style of `height` with percentages. Although, when I am trying to save the height as a variable to use, it is saving it as pixels. For example: ``` <div class="wrapper"> <div style="height:10%;">Testing 123</div> <div style="height:20%;">Testing 123</div> <div style="height:30%;">Testing 123</div> </div> $('.wrapper > div').each(function () { var height = $(this).css('height'); console.log(height); }); ``` The above code will print to the console `40px`, `80px` and `120px`. I need these values as percentages. Is there a way to do this, or should I save these values in a data attribute to use? WORKING DEMO

Original source