Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts

    can't decrement myDiv.offsetTop

    I've got a div whose position I want to decrement, but it's not working:

    myDiv.offsetTop--;

    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).

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    offsetTop is a read-only property

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

  • Users who have thanked devnull69 for this post:

    gib65 (03-15-2012)

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks devnull


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •