Mailing List Archive


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

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



Dave,

Just for kicks, I tried it too, and got the same results as Ruben.  The code snippet you gave didn't work verbatim, so for reference, this is what I used:

<html>
<body>

<div id="containerDiv">asdf</div>
<script type="text/_javascript_">

var keys = [1, 2];
var output = '';

for (var key in keys)
{
   output = output.concat('<div id="1">\n<div id="2">\n<div id="3">qwer\n</div>\n</div>\n</div>\n');
}

alert(output);
document.getElementById("containerDiv").innerHTML = output;
alert(document.getElementById("containerDiv").innerHTML);


</script>

</body>
</html>



I'm not convinced that it's the browser reformatting the innerHTML, as the html in the outer is basically valid (barring the ids), and while browsers do seem to adjust html formatting to render it, I've never seen anything like that.

Can you try out your example here:
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_concat

and then paste the exact left-hand-side code that we can all execute for ourselves in the same place to help debug the results?


 -Jdbk




On Wed, Dec 15, 2010 at 9:40 AM, Dave M G <dave@example.com> wrote:
Marco, David, Ruben,

Thank you for responding.

Just for clarity, the divs all have classes, not IDs, and I removed the
last forward slash at the end of the code that might have been causing
trouble.

So I'm pretty sure I've got the HTML syntax right.

Also, I dumped the content of my output variable to console.log() and it
seems to be formatting correctly, so Marco's suggestion that innerHTML
is doing some kind of validation seems to be right. The content of the
variable is right, but innerHTML is parsing it into crap.

So I've been looking for ways to write the variable into the div, and
everything works in some weird way. I've tried insertBefore (doesn't
seem to like nested divs), writeIn (clobbers the whole page), and
appendChild (don't know what the heck it's doing).

Isn't there some way you can just dynamically write a chunk of prepared
HTML into an existing page? The chunk of HTML I'm writing comes from a
JSON returned from the server, so I want to be able to rewrite the div
contents whenever I get new data.

--
Dave M G

--
To unsubscribe from this mailing list,
please see the instructions at http://lists.tlug.jp/list.html

The TLUG mailing list is hosted by the award-winning Internet provider
ASAHI Net.
Visit ASAHI Net's English-language Web page: http://asahi-net.jp/en/


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links