I've created an element(image div) called 'bunny', an input form and a fieldset. I also have a localhost web server which runs my websocket server for my chat. I'm trying to implement a function where for every message(which are spans) sent, the bunny element is placed beside each message.
The problems I've encountered doing this are:
Since the messages are span, the bunny element duplicates itself and is appended to each span instead of just the end of the message.
The bunny element doesn't sit exactly beside the message, it is usually below the span on a new line, I've tried appendTo and InsertAfter in JS
HTML:
<div id="bunny">
</div>
<input id="message" type="text" />
<button type="button" id="movebunny">Bunny</button>
<fieldset id="showMsg" >
<!--messages are shown here-->
</fieldset>
JAVASCRIPT
var messages;
var form;
var inputBox;
function log_msg(msg) {
messages.appendChild(document.createElement("span")).innerHTML = msg;
}
function doInit() {
inputBox = document.getElementById("message");
messages = document.getElementById("messages");
form = document.getElementById("message-form");
var s;
...
//there's a bit more to the js code but they're all just to connect to server//
Would greatly appreciate any suggestions to getting element at the end of each message sent on click of a button, thanks!