SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setAttribute(offsetTop) - Error: Not Implemented

    I'm trying to set the top position of an element within its parent using JavaScript. Firefox doesn't do anything but throws no error. IE gives the error "Not implemented". Any ideas?

    Here's my code: Demo

    I'm trying to make the content of the middle section slide up and down within its parent depending on the link selected. I've had partial success in IE when setting top margin to a negative value, but even that has issues.


    Thanks,

    Andy
    From the English nation to a US location.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    offsetTop isn't an HTML attribute, which is what IE's error is telling you. Whatever you're trying to do (not sure what this is based on your explanation), it looks like you should do it with CSS (margins most likely). This means either using the style object or swapping/adding/removing class names, or maybe an ID.

    If you want things to move around without affecting surrounding elements, you will need to use absolute positioning.

  3. #3
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Raffles. I'm already using absolute positioning and trying to change the value of "top". As offsetTop is a read-only property, I'm trying to get around that by using setAttribute. Is there a better way to set that value?

    I've also tried changing the top margin to a negative value, but I wind up with some strange overlapping content.
    From the English nation to a US location.

  4. #4
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I see that in the past I've successfully set the value of [element].style.top so perhaps that's not my problem here.
    From the English nation to a US location.

  5. #5
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seem to be answering my own question here (which is probably a good thing anyway) but this achieves the desired result using a different method: Demo.

    I'm still interested in getting the original method to work as it seems more elegant with less overhead, but the urgency has gone away now I have a work-around.
    From the English nation to a US location.

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If something is a read-only property, you can't "get around it". offsetTop is a measurement of how far the element in question is from the top of its parent element.

    What you have done is the "accepted" way of doing this: switching the "display" from "block" to "none". Messing about with anything else would be silly. To make it slightly cleaner you can simply add and remove a class of "show" or "hide" to trigger the relevant "display" value.

  7. #7
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for pointing out my silliness. I'm sure the accepted way is the only way.
    From the English nation to a US location.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    By definition because it is the accepted way, there have to be unacceptable ways as well. The accepted way is only as such because the unacceptable ways all have issues that are more troublesome than the accepted.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I didn't mean to say you had been foolish in any way, merely that doing it any other way would be more time-consuming, fragile and possibly non-cross-browser too.


Bookmarks

Posting Permissions

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