Created
September 21, 2016 23:30
-
-
Save kwhinnery/08b9da6f7ff6c2e70909425a9e0a50b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html | |
head | |
title Socket.io Example | |
body | |
h1(class="something") Socket.io Example | |
input#msg(type="text") | |
button send message | |
#messages | |
script(src="/socket.io/socket.io.js") | |
script(src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js") | |
script. | |
var socket = io(); | |
$('button').on('click', function() { | |
socket.emit('message', $('#msg').val()); | |
}); | |
socket.on('message', function(msg) { | |
var $span = $('<div>'); | |
$span.text(msg); | |
$('#messages').append($span); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment