Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Javascript and I have different ideas about what "concatenate" means.



TLUG,

Me and Javascript are disagreeing, and I'm sure I'm right about this.

I need to output a sequence of nested <div> tags. The desired output is
this:

<div id="1">
   <div id="2">
        <div id="3">
        </div>
    </div>
</div>
<div id="1">
   <div id="2">
        <div id="3">
        </div>
    </div>
</div>

To do that, I've got my code set up like this:
output = "";
for (var key in theVariableThatIsBeingUsedForThis)
{
    output = output.concat('<div id="1">\n\
   <div id="2">\n\
        <div id="3">\n\
        </div>\n\
    </div>\n\
</div>\n\')
}
document.getElementById("containerDiv").innerHTML = output;

What I'm getting from this is:
<div id="1">
   <div id="2">
        <div id="3">
            <div id="1">
                <div id="2">
                    <div id="3">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

So it's as if the concat() function in Javascript is somehow looking at
the tree of div tags and adding it onto the outermost branch, instead of
doing what I wanted it to do, which is just treat it like a string and
append it to the end.

What the heck? Either I've got some bug that I don't see, or the people
who have Javascript have a completely different idea of than I do of
what it means to concatenate strings.

Any ideas on what the heck is going on here? Am I wrong about what I
should expect from the way I've set up my code?

Any advice would be much appreciated.

-- 
Dave M G


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links