I am having trouble figuring out how to incorporate a jQuery command that will display the entered message in the chat body when the user presses the enter key. I want the message to be formatted in a 'msg_b' style. I attempted using the following code, but it did not work:
$('textarea').keypress(function(e){
if(e.keyCode==13){
var msg=$(this).val();
$this.val("");
$("<div class='msg_b'>"+msg+"</div>").insertBefore('.msg_insert');
}
});
Here is an excerpt from my HTML script:
<div class="msg_head">Rishabh Sood
<div class="close"> x </div>
</div>
<div class ="msg_wrap">
<div class ="msg_body">
<div class ="msg_a">Hey bro wassup!</div>
<div class ="msg_b">All nice!</div>
<div class="msg_insert"></div>
</div>
<div class="msg_footer"><textarea class="msg_input" rows="4" placeholder = "Enter Message"></textarea></div>
</div>