Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 10th, 2008, 11:55 PM
Rubikzube
Guest
 
Posts: n/a
Default 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.

  #2  
Old March 11th, 2008, 11:15 AM
SAM
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.