javascript - jquery - append html doesn't append the empty String inside the div -


i doing chat project in java.

using server response through jquery-ajax , creating html , append html div.

my jquery - html alert without empty string-name(note id='user' in alert) ,

enter image description here

after appending in chat area ,

enter image description here

after jquery-html alert with empty string-name(note id='user' in alert) ,

enter image description here

after appending in chat area ,

enter image description here

my jquery creating html ,

function send(name , message , time){     //name = $("#name").val();     //message = $("#message").val();      var user = "<div id='user' class='fontstyle'>"+name+"</div>";     var msg = "<div id='msg'  class='fontstyle'>"+message+"</div>";     var timestamp = "<div id='time'  class='fontstyle'>"+time+"</div>";      var row = "<div id='msgset' >"+ user + msg + timestamp +"</div>";      alert(row);     return row;  } 

there no empty string present in chat area.

hope our stack members me.

you can escape html string keeps white spaces. see details here.

or can trim message string (=remove spaces @ beginning , end of it) such instruction, , manualy add spaces (with &nbsp; code inside div, span, ...):

s.replace(/\s+/g, ' '); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -