Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vanilla JS for DOM manipulation instead of JQuery #428

Merged
merged 1 commit into from May 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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