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?

2

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

3 Comments

Ah great thanks that [0] did it, I already tried to do something like that but never knew [0] has to be before that
@Enthu its already answered and accepted.
@NidhinJoseph , hi , I have commented , it is not working fine for more than one box , I have commented in the last, please help

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.