Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old March 11th, 2008, 12:55 AM
Rubikzube
Guest
 
Posts: n/a
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.
  #2  
Old March 11th, 2008, 12:15 PM
SAM
Guest
 
Posts: n/a

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


Rubikzube a écrit :
Quote:
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="function_to_insert();
return false;">
^^^^^^^^^^^^^

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

--
sm
Closed Thread