0

How to make document.getelementbyid.style.top a number? I'm trying to make document.getElementById.style.top to be a number without px. For example if document.getElementById.style.top is 100px, I want to make a variable that is 100 without px.

I tried to do this, but it wasn't working.

HaibaoM
  • 13
  • 4
  • Use the `replace()` method to remove the `px` from it, then convert that to a number with `parseInt()` – Barmar Mar 31 '22 at 16:10
  • 1
    Or just call `parseInt()`, it will ignore the `px`. – Barmar Mar 31 '22 at 16:10
  • 1
    Does this answer your question? [Get a number for a style value WITHOUT the "px;" suffix](https://stackoverflow.com/questions/8690463/get-a-number-for-a-style-value-without-the-px-suffix) Googling for "style.top as number" had this question as the first result. – Daniel F Mar 31 '22 at 16:20

1 Answers1

0
parseInt(document.getElementById.style.top)
scripter2021
  • 341
  • 2
  • 10