At this moment, the width()
function in jQuery as well as its variations all return values in pixels. The same applies when using the css('width')
method.
I have elements that are styled in external .css
files, and there is no way for me to determine if they are styled in percentages or pixels. If an element has a width set in percentage or no width at all, I need to retrieve a percent value.
For instance, consider the following:
.seventy { width: 70%; }
.pixels { width: 350px; }
<div class="seventy"></div>
<div class="pixels"></div>
<div class="regular"></div>
In this scenario, these would be the desired outcomes:
$('.seventy').method() //=> '70%'
$('.pixels').method() //=> '350px'
$('.regular').method() //=> '100%' due to default behavior of block elements
Is there a built-in method in jQuery that can help me achieve this outcome? Alternatively, is there a custom approach that could be taken?