Reputation: 3731
I'm trying to create a line break in the html page after data is received from the server, using append method. This is a snippet of my code (jquery):
ws.onmessage = function(evt) $("#display").append("message: " + evt.data);
This is the div in the html:
<div id ="display"></div>
I'm a newbie, so please forgive the simplicity of the question.
Thanks
Upvotes: 0
Views: 882
Reputation: 27667
Technically speaking a linebreak won't be displayed in your HTML, you would need to use a <br/>
tag to create a break. In JavaScript a new line character would be \n
, but you probably want to use:
ws.onmessage = function(evt) $("#display").append("message: " + evt.data + "<br/>");
If you are pre-formatting the <div>
as if it were a <pre>
tag and actually want a new line:
ws.onmessage = function(evt) $("#display").append("message: " + evt.data + "\n");
Your HTML for your div is a little off as well, you should remove the space between id
and ="display"
<div id="display"></div>
Upvotes: 1
Reputation: 1129
try this:
ws.onmessage = function(evt) $("#display").append("message: " + evt.data + "<br />");
another option could be
ws.onmessage = function(evt) $("#display").append("<p>message: " + evt.data + "</p>");
Upvotes: 3