I'm implementing a little chat application where I receive messages from a server, which I would like to display to a user. As I'm more of a backend guy, and lacking experience in frontend development, I don't know which element would be suited best to output the text.
Two options e to my mind:
- Using a plain
div
- Using a
textarea
(as far as I understand, this is intended to be used for input).
(Would also be nice if I could somehow fade in the text using JQuery).
I'm implementing a little chat application where I receive messages from a server, which I would like to display to a user. As I'm more of a backend guy, and lacking experience in frontend development, I don't know which element would be suited best to output the text.
Two options e to my mind:
- Using a plain
div
- Using a
textarea
(as far as I understand, this is intended to be used for input).
(Would also be nice if I could somehow fade in the text using JQuery).
Share Improve this question edited Mar 29, 2012 at 17:45 gdoron 150k59 gold badges302 silver badges371 bronze badges asked Mar 29, 2012 at 17:18 helpermethodhelpermethod 62.4k71 gold badges199 silver badges280 bronze badges3 Answers
Reset to default 4- For readonly messages- better use
<div>
- otherwise use
<textarea>
\ textbox(<input type="text"...>
).
Fading it is simple, if the element id is foo
:
$('#foo').fadeIn();
Use a tag for the content and with Jquery you could append a span or a new paragraph tag for every new message:
<div id="chatContent">
</div>
Then in JQuery you could do:
function chatMessageRecieved(message) {
$("#chatContent").append("<p> " + messsage + "</p>")
}
You have to use a div, textarea is effectively for input
For jquery : http://api.jquery./fadeTo/
Ex :
$('#div').fadeTo('slow', 1);