In my comment box, I want user comment with emoticon and display yet. But textarea can support only plain text, so I add a div where comment preview before submit.
Here in my work:
var smileys = {
  ':)': '<img src="smilies/smile.gif" border="0" alt="" />',
  ':-)': '<img src="smilies/smile.gif" border="0" alt="" />'
};
$(document).ready(function() {
  $(".chat > textarea").bind("keyup", function(e) {
    $(".chat > div").html(smilyMe($(".chat > textarea").val()));
  });
});
function smilyMe(msg) {
  //smiley replace
  return msg.replace(/(\:\)|\:-\)|\:D|\:-D|\blol\b|\:-\||\:-\(|\;-\))/g, function(all) {
    return smileys[all] || all;
  });
}div#maintbox {
 border: 2px solid #ccc;
 padding:0px;
 overflow:auto;
 width: 450px;
 margin-bottom:3px;
}
div.chat {
  width: 400px;
}
div.chat > div {
  width: 400px;
  color:#000000;
  padding: 0px 0px 5px 0px;
  z-index:997;
}
div.chat > textarea {
  width: 400px;
  background: transparent;
}<div id="maintbox">
<div class="chat">
  <div>
  </div>
    <textarea name="comment" rows="2" tabindex="4" id="comment" placeholder="Type here..."></textarea>
</div>
  <div align="right" style="width:30px;float:right;"><img src="images/camera.png" width="25" alt="Upload image" id="uploadMedia" style="padding:2px;cursor:pointer;" /></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>My Question
When I press enter to go 2nd line and write any 'text', Preview div cannot display 'text' on 2nd line, Its display 'text' on same line.
 
     
    
` element in the `div`. – emerson.marini Jan 27 '15 at 16:18
tags?](http://stackoverflow.com/questions/784539/how-do-i-replace-all-line-breaks-in-a-string-with-br-tags) – emerson.marini Jan 27 '15 at 16:18
` element, because the `div` content is rendered as `HTML`, and not plain text. – emerson.marini Jan 27 '15 at 16:22
'); for test Please. – koc Jan 27 '15 at 16:29