admin管理员组文章数量:1325236
I have some content like this
var p =
I myself
Abhimanyu Singh
Yadav
when I m trying to insert into as innerHTML
to some div
the whole content appears in one line. I'm using <pre>
tag to avoid this problem. But need some appropriate solution.
I have some content like this
var p =
I myself
Abhimanyu Singh
Yadav
when I m trying to insert into as innerHTML
to some div
the whole content appears in one line. I'm using <pre>
tag to avoid this problem. But need some appropriate solution.
-
Can I understand your question as "When inserting multi-line text via Javascript it displays in one line. How can I insert
<br>
tags instead?" – deceze ♦ Commented Aug 10, 2009 at 5:50 - Can you please post the code for this? – rahul Commented Aug 10, 2009 at 5:50
- I don't think its related to question formatting. – rahul Commented Aug 10, 2009 at 5:52
2 Answers
Reset to default 5You can replace the new line characters with html BR elements (<br />
):
document.getElementById('myDiv').innerHTML = p.replace(/\n/g, '<br />');
var p = "i myself<br />Abhimanyu Singh<br />Yadav";
updated to make andrew happy. a still non-semantic answer that is more semantic.
本文标签: javascriptHTML ltbrgt and innerHTMLStack Overflow
版权声明:本文标题:javascript - HTML <br> and innerHTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742169298a2426417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论