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
Add a ment  | 

5 Answers 5

Reset to default 5

To 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