0

I have this code:

<div id="progres-bar" class="progres-bar" value="90"></div>

I want to get value from this element where value="90", so the output should be 90 using javascript. I tried to make this with the below way:

document.getElementById("progres-bar").value;

but it didn't worked!

Ajay Lingayat
  • 1,465
  • 1
  • 9
  • 25
  • 2
    Technically a `
    ` doesn't *have* a `value`. Semantically what you probably want instead is `data-value="90"`, which would make the usage more explicit as well. Browsers may be forgiving of what you're doing here and it may "work", but it's always better to start with valid markup instead of relying on browsers handling invalid markup correctly.
    – David Dec 28 '20 at 13:57

1 Answers1

4

You can use getAttribute() function.

const value = document.getElementById("progres-bar").getAttribute("value");
console.log(value);
<div id="progres-bar" class="progres-bar" value="90"></div>
0stone0
  • 34,288
  • 4
  • 39
  • 64