NodeChat

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 79afe73d21a3c67c78f9b46a75673f9db02e3e0f
parent 339d2b1ad79133a67c27a558dae97a58405a672e
Author: Damien Arrachequesne <damien.arrachequesne@gmail.com>
Date:   Wed,  8 Mar 2017 06:54:42 +0100

fix(*): run the js once the dom is loaded

Diffstat:
Mindex.html | 18++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/index.html b/index.html @@ -21,14 +21,16 @@ <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> <script src="https://code.jquery.com/jquery-1.11.1.js"></script> <script> - var socket = io(); - $('form').submit(function(){ - socket.emit('chat message', $('#m').val()); - $('#m').val(''); - return false; - }); - socket.on('chat message', function(msg){ - $('#messages').append($('<li>').text(msg)); + $(function () { + var socket = io(); + $('form').submit(function(){ + socket.emit('chat message', $('#m').val()); + $('#m').val(''); + return false; + }); + socket.on('chat message', function(msg){ + $('#messages').append($('<li>').text(msg)); + }); }); </script> </body>