Skip to content

Commit

Permalink
chore(examples/socket.io-chat-app): use vanilla JS instead of jquery …
Browse files Browse the repository at this point in the history
…for DOM manipulation
  • Loading branch information
kresnasatya authored and OlliV committed Feb 12, 2020
1 parent 255b8ca commit 9a3204b
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions examples/socket.io-chat-app/index.html
Expand Up @@ -24,21 +24,18 @@
</form>

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>

<script>
$(() => {
var socket = io()
var socket = io()

$('form').submit(() => {
socket.emit('chat message', $('#m').val())
$('#m').val('')
document.querySelector('form').addEventListener('submit', (e) => {
e.preventDefault();
socket.emit('chat message', document.getElementById('m').value);
document.getElementById('m').value = '';
});

return false
})
socket.on('chat message', msg => {
$('#messages').append($('<li>').text(msg))
})
socket.on('chat message', msg => {
document.getElementById('messages').insertAdjacentHTML('beforeend', `<li>${msg}</li>`);
});
</script>
</body>
Expand Down

0 comments on commit 9a3204b

Please sign in to comment.