Let's say I have something.style.top = "Ypx", how to extract and increment that Y, if Y can be either negative or positive? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Let's say I have something.style.top = "Ypx", how to extract and increment that Y, if Y can be either negative or positive?

Y < innerHeight

5th Sep 2020, 7:41 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
2 Answers
+ 6
something.style.top = parseInt(something.style.top)+1 + "px" Or something.style.top = +something.style.top.slice(0,-2)+1 + "px"
5th Sep 2020, 7:51 AM
Namit Jain
Namit Jain - avatar
+ 2
parseFloat might be better.
5th Sep 2020, 8:15 AM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar