admin管理员组文章数量:1319488
I have this really big text where I want to add line breaks in order to look better on my application. I have tried using
"<br>", "\n"
to cut the text in pieces. I have ven tried to change the width of the span but nothing seems to be working. What am I doing wrong? Any help appreciated.
<span id="instr" style="color: white; font-size: 15pt;"></span>
<script type="text/javascript">
function instructions(){
....
document.getElementById("instr").textContent = "Really biiiiiiiiiiiiiiiiiiiiiiiiig text here";
}
</script>
I have this really big text where I want to add line breaks in order to look better on my application. I have tried using
"<br>", "\n"
to cut the text in pieces. I have ven tried to change the width of the span but nothing seems to be working. What am I doing wrong? Any help appreciated.
<span id="instr" style="color: white; font-size: 15pt;"></span>
<script type="text/javascript">
function instructions(){
....
document.getElementById("instr").textContent = "Really biiiiiiiiiiiiiiiiiiiiiiiiig text here";
}
</script>
Share
Improve this question
asked Feb 12, 2013 at 16:20
niaoyniaoy
1012 silver badges9 bronze badges
0
5 Answers
Reset to default 5To set <br />
line breaks you need to use innerHTML
property:
document.getElementById("instr").innerHTML = "Really<br />biiiiiiiiiiiiiiiiiiiiiiiiig<br/ >text here";
You could use the CSS white-space
property to wrap text. See here for more information: https://developer.mozilla/en-US/docs/CSS/white-space
Use document.getElementById("instr").innerHTML
to insert <br>
.
since span is inline element, I would not use it. I would try div or p elements. If you have to, look into word-wrap property
Just use innerText
instead of textContent
. Then you can use \n
.
document.getElementById("instr").innerText = "Really biiiiiiiiiiiiiiiiiiiiiiiiig\n text here";
Or use innerHTML
along with <br/>
.
document.getElementById("instr").innerHTML = "Really biiiiiiiiiiiiiiiiiiiiiiiiig<br/> text here";
jsFiddle: http://jsfiddle/phCmH/
本文标签: htmlJavascript linebreak not workingStack Overflow
版权声明:本文标题:html - Javascript line-break not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742058946a2418465.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论