/    Sign up×
Community /Pin to ProfileBookmark

"center" and DOM

I have a div to which I attach a DOM constructed table as a child (“mydiv.appendChild(mytable)”). The div was created with normal html this way:

[code]
<div><center>
[/code]

However, the center tag does affect the DOM object, just ones that are inserted with normal mark-up.

Is there a solution???

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledApr 07.2009 — you are inserting the table in the div, not in center element. so you get something like <div><table>...</table><center></center></div>. to insert it inside center tag make sure there is no space between <div> and <center>, just like you show in your code. to append to table you would do mydiv.[b]firstChild[/b].appendChild(...);
Copy linkTweet thisAlerts:
@akashiraffeeauthorApr 07.2009 — to insert it inside center tag make sure there is no space between <div> and <center>, just like you show in your code. to append to table you would do mydiv.[b]firstChild[/b].appendChild(...);[/QUOTE]
it is just like i showed it (or at least, two consecutive document.write statements produce the <div> and then the <center> tag), but apparently <center> is still not the child of the div, since mydiv.firstChild (after <div><center>) is undefined. Even when I used DOM code to produce the center and made it the firstChild of the div, this <center> did not apply to the next child (the table).

However, making <center> the child of the <div> and the <table> the child of the <center> works.
Copy linkTweet thisAlerts:
@ZeroKilledApr 07.2009 — if still have problem post the significant code: the script that write the elements, and the code that make the call for appending the table, or anything else that involve the operation you want.
Copy linkTweet thisAlerts:
@akashiraffeeauthorApr 07.2009 — No, everything's good now -- altho I just noticed my Original Post should have read "does NOT affect DOM objects" which apparently it is too late to edit now!

Anyway, thanks, your post got me thinking in the right direction.
Copy linkTweet thisAlerts:
@felgallApr 07.2009 — You would simplify things greatly if you got rid of the obsolete <center> tag and just apply [b]margin:0 auto[/b] to the div via CSS so as to do the cerntering properly. That way you wouldn't haveunnecessary HTML tags making the DOM manipulations more complicated than they need to be.
×

Success!

Help @akashiraffee 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...