
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.
- Date: Wed, 15 Dec 2010 23:16:51 +0900
- From: Dave M G <dave@example.com>
- Subject: [tlug] Javascript and I have different ideas about what "concatenate" means.
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7
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