0

I am trying to update the width of a div with a javascript variable but cannot understand how to format it properly.

This way works where you define a fixed percentage.

divider.style.width = '20%';

But I am unable to use a variable like this:

var progress = 40/100;
divider.style.width = progress;

Can anyone point out the proper way to format a float variable into a string that the width property will understand?

1 Answer 1

2

Try:

divider.style.width = (progress * 100) + '%';
Sign up to request clarification or add additional context in comments.

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.