4

I'm having difficulty in selecting the "style=:width: 10%" value in jquery for progressbar element in bootstrap.

<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 10%;"> <span class="sr-only">0% Complete</span> </div>

This is what I have tried so far, $(".progress-bar[style*=width]"); but it returns the entire div.

My goal is to target that value and change it via Ajax.

Here is a jsfiddle boilerplate for your reference.

Thanks

1
  • How exactly would you target a value, and change it with ajax, the code you've posted is supposed to return the entire element ? Commented Jan 3, 2016 at 17:21

2 Answers 2

2

Use a filter instead. Try not to use attributes(other than id and class) as selectors.

<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 10%;">

SCRIPT:

$('.progress-bar').filter(function(){ return $(this).css('width') === "10%"; });

http://learn.jquery.com/using-jquery-core/selecting-elements/ has some notes about this mentioning concerns with certain selectors being potentially slower. Something worth reviewing.

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

Comments

1

Try like following.

Get width

var width = $(".progress-bar")[0].style.width;

Set width

$(".progress-bar")[0].style.width = '90%';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.