skip to Main Content

Hello I have this CSS code:

.bar .progress-line.html span {
  width: 78%;
}

How can I change the width from javascript? I have tried many ways like

$(".bar .progress-line.html span").css("width", "10%");

But nothing is found.

I also tried this:

$(".bar .progress-line.html span").css("width", "10%");

but nothing happens.

Original example: https://codepen.io/Prashal9499/pen/oNWzPqR

2

Answers


  1. You have to set a comma in between the class names while targeting multiple elements. Here is an updated version of what you have done so far.

    $(".bar, .progress-line, .html, span").css("width", "10%");
    
    Login or Signup to reply.
  2. If you’re trying to change the text, see the link in my comment to your original post.

    You can do it manually like this:

    New class:

    .progress-line.html span.change::after {
        content: "55%";
    }
    

    jQuery

    $(".progress-line.html span").css("width", "55%");
    $(".progress-line.html span").addClass("change");
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search