/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Elements added by JS not visible in page source.

I’m trying to have a scroll function (scrollIntoView(true)) that scrolls to an element created by JS. This isn’t working because when I use document.createElement the element’s html doesn’t show up in page source so I can’t find it using document.getElementById.

What should I do?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineNov 01.2010 —  I use document.createElement the element's html doesn't show up in page source so I can't find it using document.getElementById.
[/QUOTE]
Dynamically created elements don't show in page source nor do they need to in order to be referenced. Post all your code.
Copy linkTweet thisAlerts:
@hwaforumtkauthorNov 01.2010 — Thanks for the reply.

I actually found an alternative to what I was doing.

To clear up what I had a problem with:

I had a function that did this:
[CODE]var img = document.createElement( "img" );
img.src = "******.jpg";
var a = document.createElement( "a" );
document.getElementById( "ytplayer_div2" ).appendChild( a );[/CODE]


And a function that did this
[CODE]var element = document.getElementById(paraId);
element.scrollIntoView(true);[/CODE]


The elements created by the first function didn't appear in page source so I couldn't use the second function to scroll to them.

Regardless I'm doing it a different way now. Thanks.
×

Success!

Help @hwaforumtk 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.19,
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,
)...