/    Sign up×
Community /Pin to ProfileBookmark

how to use scrollIntoView on dynamic HTML Elements

Hey,

in my script I am adding div elements dynamically to the DOM. After creation I want the browser to scroll them into view using JS function scrollIntoView.

The problem is that calling scrollIntoView right after calling document.body.appendChild(newElement) doesn’t work.

Looking forward to your help!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@007JulienJan 08.2013 — Several times, this genre of problem can be solved with a setTimeout to execute the scroll some milliseconds after the end of the script. Still the page has to can scroll !
Copy linkTweet thisAlerts:
@projs1authorJan 08.2013 — Several times, this genre of problem can be solved with a setTimeout to execute the scroll some milliseconds after the end of the script. Still the page has to can scroll ![/QUOTE]

Thanks, setting Timeout solved my problem but is there no better solution for that?
Copy linkTweet thisAlerts:
@007JulienJan 09.2013 — «Delaying the execution (even by 0 miilliseconds) allows screen updates to occur before the processing begin !» It's not necessary a bad solution ! Read, for example, this page «Processing vs Responsiveness».
×

Success!

Help @projs1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...