html label inserting newline
I'm trying to set some text to a label dynamically using jQuery. But i can't get the <br>
or \n
to render and give me new lines. It all shows up on the same line and wraps.
here i开发者_开发知识库s my code On JsFiddle
My html:
<label id="myLabel" />
My Javascript:
$("#myLabel").text("This is my first line \n This should be my second line.");
text()
will escape any html code, so instead use html()
$("#myLabel").html("This is my first line <br /> This should be my second line.");
The problem is that .text()
will ignore your html. You should use .html()
, soy u can put whatever html you want inside an element. So you'd have:
$('#myLabel').html('This is my first line <br/> This should be my second line.');
Hope this helps. Cheers
Try this instead:
$('#myLabel')
.html('this is my first line<br/>This should be my second line.');
精彩评论