appendChild behavior

S

sicapitan

The appendChild to the row_container works a treat, while
column_container remainds blank, and it appears at the bottom of my
document

Hmm, here is my code :

function initGrid()
{
row_id = 1;

row1 = Builder.node('div',{id:''+row_id, className:'grid_start_row'});
row2 = Builder.node('div',{id:''+row_id,
className:'grid_row_inactive'});

strcol = "addColumn('col"+fieldcount+"');";

column = Builder.node('div',{id:'col'+fieldcount,
className:'grid_start_col'}, [
Builder.node('a', {href:'#', className:'hvr', onclick:''+strcol,
title:'Create a new column'},'add column'), [
Builder.node('input', {type:'text', id:'title'+fieldcount,
className:'colheader'}
)]
]);

$("row_container").appendChild( row1 );
$("row_container").appendChild( row2 );

$("column_container").appendChild( column );

}

my html:

<div id="row_container"></div>
<div id="column_container"><div>

is this because i'm creating a multiline builder node? the output is
fine, its just its not putting it in the div!

Any ideas?
 
R

Richard Cornford

sicapitan said:
The appendChild to the row_container works a treat, while
column_container remainds blank, and it appears at the bottom
of my document

Hmm, here is my code :

function initGrid()
{
row_id = 1;
row1 = Builder.node('div',{id:''+row_id, className:'grid_start_row'});
<snip>

There is little point posting this code without the definitions of the
objects/methods/functions it uses as any errors/misconceptions they
contain, and even their actual behaviour may be significant.
my html:

<div id="row_container"></div>
<div id="column_container"><div> ^^^^^
is this because i'm creating a multiline builder node? the output is
fine, its just its not putting it in the div!

It is always difficult to tell whether posted snippets of code are the
actual original code or just reproductions into which errors may have
been introduced (hence the recommendation to present minimal test-case
pages that demonstrate issues in a reproducible form). However, if that
HTML is what you are actually using then the fact that what appears to
have been intended to be a closing DIV tag is missing the slash, and so
is actually a new opening DIV tag, is capable of explaining your
symptoms.

That second opening DIV tag will start a DIV element that is a child of
your column_container element and probably contains the rest of the
document (it will not be forced closed until the closing BODY tag is
encountered. As a result, when you append a new child to
column_container you are adding that child after the 'accidental' DIV
and as the 'accidental' DIV contains the rest of the document the new
child will appear to be at the end of the document.

As DIV elements do not have optional closing tags validating your
mark-up should have flagged that error and so avoided this issue.

Richard.
 
S

sicapitan

haha thanks, a simple /

i think i should use the helpers in textmate more haha

thanks richie!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top