Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Firebase Tutorial
<!doctype html>
<script src=''></script>
<script src=''></script>
<link rel='stylesheet' type='text/css' href='/resources/tutorial/css/example.css'>
<div id='messagesDiv'></div>
<input type='text' id='nameInput' placeholder='Name'>
<input type='text' id='messageInput' placeholder='Message'>
var myDataRef = new Firebase('');
$('#messageInput').keypress(function (e) {
if (e.keyCode == 13) {
var name = $('#nameInput').val();
var text = $('#messageInput').val();
myDataRef.push({name: name, text: text});
myDataRef.on('child_added', function(snapshot) {
var message = snapshot.val();
displayChatMessage(, message.text);
function displayChatMessage(name, text) {
$('<div/>').text(text).prepend($('<em/>').text(name+': ')).appendTo($('#messagesDiv'));
$('#messagesDiv')[0].scrollTop = $('#messagesDiv')[0].scrollHeight;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment