View Full Version : can't decrement myDiv.offsetTop

03-15-2012, 05:49 PM
I've got a div whose position I want to decrement, but it's not working:


doesn't work.

I'm using offsetTop because myDiv.top is undefined, myDiv.style.top is "". myDiv.offsetTop is the only field I've found that has a valid value. But when I tell it myDiv.offsetTop-- the value doesn't change. If I tell it myDiv.offsetTop = myDiv.offsetTop - 1, I get no results either (although if I do an alert on myDiv.offsetTop - 1, it gives me the expected value; why this value can't be assigned back to myDiv.offsetTop is a mystery).

03-15-2012, 10:24 PM
offsetTop is a read-only property

To get the current position, you can read offsetTop and then set style.top to a new position

03-15-2012, 10:27 PM
Thanks devnull