tags:

views:

441

answers:

1

I am trying to implement a browser based chat system with jQuery. I want to poll the server for new messages and append them to the bottom of a div. I have two problems.

  • I can't get it to append text to the div
  • I don't know how to keep the div scrolled to the bottom as the text gets appended

Here's the relevant clip of my HTML:

<div id="main">
 <form action='post.php' method='post'>
  <div id='messages'>stuff</div><br />
  <input type='text' name='usertext' />
 </form>
</div>
+3  A: 

I'm not sure what you're missing here.

$(selector).append('<div class="message">sometext</div>');

And how to scroll to the bottom of a div

Ben Shelock
Based solely on your provided code, Ben's example would expand to $('div#main div#messages').append('<div class="message">sometext</div>');
eidylon