I am trying to prepend a string but it is invisible for some reason. Anyone know what is wrong with it?
$('#someelement').prepend('<div id="chunk" chunk_id="302724de111fd8fd4a7.92282758">
<a shoutbox_id="302724de111fd8fd4a7.922827开发者_Go百科58" id="show-replies">
<img src="images/show_more.png"></a>
<a shoutbox_id="302724de111fd8fd4a7.92282758" id="reply">Add Comment</a>
<li class="shoutbox-list-creator" id="list-13">
<span class="shoutbox-list-nick">
<a href="statistics.php?user=g">g</a>
</span>
<span class="date" id="1306595842"> 0 seconds ago
</span><br>
<span class="msg">i said</span><br />
<span class="clear"></span>
</li><hr>
</div>');
You need to put all the HTML on a single line (remove the line breaks).
The other choice is to put a backslash at the end of every line. This will work:
$('#someelement').prepend('<div id="chunk" chunk_id="302724de111fd8fd4a7.92282758"> \
<a shoutbox_id="302724de111fd8fd4a7.92282758" id="show-replies"> \
<img src="images/show_more.png"></a> \
<a shoutbox_id="302724de111fd8fd4a7.92282758" id="reply">Add Comment</a> \
<li class="shoutbox-list-creator" id="list-13"> \
<span class="shoutbox-list-nick"> \
<a href="statistics.php?user=g">g</a> \
</span> \
<span class="date" id="1306595842"> 0 seconds ago \
</span><br> \
<span class="msg">i said</span><br /> \
<span class="clear"></span> \
</li><hr> \
</div>');
The content is never added to the DOM, that's why it is not visible.
Running the code gives:
Uncaught SyntaxError: Unexpected token ILLEGAL
You cannot split your string over multiple lines like this.
It works if everything is on one line: http://jsfiddle.net/JCTpG/
When I put everything on one line it works for me: http://jsfiddle.net/
精彩评论