2

I have this element:

<div class="progress xs" style="margin-bottom: 0px; height: 3px;">
    <div class="progress-bar progress-bar-green" style="width: 100%;"></div>   
</div>

I want to get the inline css property width.

I tried to do this:

$(".progress").find(".progress-bar").css('width');

Which should return '100%' but returns 638px instead.
As you can see in my example :

console.log($(".progress").find(".progress-bar").css('width'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="progress xs" style="margin-bottom: 0px; height: 3px;">
    <div class="progress-bar progress-bar-green" style="width: 100%;"></div>   
</div>

Does anyone know how to get the 100% of the progress-bar element?

Webdeveloper_Jelle
  • 2,868
  • 4
  • 29
  • 55

1 Answers1

6

You can directly access the style property of the element to get the defined width.

console.log($(".progress").find(".progress-bar").css('width'));
console.log($(".progress").find(".progress-bar")[0].style.width);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="progress xs" style="margin-bottom: 0px; height: 3px;">
  <div class="progress-bar progress-bar-green" style="width: 100%;"></div>
</div>
Nidhin Joseph
  • 9,981
  • 4
  • 26
  • 48