I have a span like this :
<span class "message"></span>
And I am filling it from javascript like this :
message = "first message" + "\\\n";
message = message + "second message";
$(".message".)text(errorMessage);
$(".message").show();
The problem with that, is when the text is displayed on my browser, the 2 messages are on the same line, I can't insert the second with a newline. Whereas in my debug console, the text appears well on 2 lines. I have also tried the <br>
, which is worst as it's not interpreted, so I am getting a message like this :
first message br second message.
Basically, I would like to have displayed :
first message
second message
You can use <br />
and html()
to break the text on new line:
message = "first message" + "<br />";
message += "second message";
$(".message").html(errorMessage).show();
Set the HTML contents of each element in the set of matched elements.
Docs: http://api.jquery.com/html/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With