How do I avoid a scroll when removing or creating DOM elements?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rubikzube

    How do I avoid a scroll when removing or creating DOM elements?

    I have JavaScript functions on my page that insert and remove DOM
    elements, and it's causing the browser to rescroll to the top of the
    window. I was wondering what the cause of the behavior is and if
    there is a smooth workaround.

    The rescroll is happening after the insertion function, and using a
    setTimeout is just making the page shake.
  • SAM

    #2
    Re: How do I avoid a scroll when removing or creating DOM elements?

    Rubikzube a écrit :
    I have JavaScript functions on my page that insert and remove DOM
    elements, and it's causing the browser to rescroll to the top of the
    window. I was wondering what the cause of the behavior is and if
    there is a smooth workaround.
    >
    The rescroll is happening after the insertion function, and using a
    setTimeout is just making the page shake.
    <a href="#"
    onclick="functi on_to_insert();
    return false;">
    ^^^^^^^^^^^^^

    don't forget the 'return false' in your JS call
    to avoid html link fires

    --
    sm

    Comment

    Working...