Reputation: 2832
I have some JavaScript code that does some stuff, but at some point I need to do this:
$('#mySpan').text('Hello\nWorld');
Here is my HTML code:
<span id="mySpan"></span>
So I can finally get this:
Hello
World
The problem is that HTML is not detecting the breakline inserted from the JavaScript. I also tried this:
$('#mySpan').text('Hello<BR/>World');
But it doesn't work either.
How should I do it?
Upvotes: 1
Views: 192
Reputation: 187110
What about
$('#mySpan').html('Hello<br/>World');
?
text only sets the text contents whereas html sets the HTML contents.
Upvotes: 4
Reputation: 382909
Why don't use try this initially on:
$('#mySpan').html('Hello<br />World');
Upvotes: 0