Skip to main content
Skip to main navigation

Firebase Console Demo

var ref = new Firebase("https://light-up-the-web.firebaseio.com/");
var demoRef = ref.child('demo');

var newKey = demoRef.push('new data').key();

// Get value by key
demoRef.child(newKey).once('value',function(snap){ 
	console.log(snap.val()) 
});

// Get newest value
demoRef.limitToLast(1).once('value',function(snapshot) {
	snapshot.forEach(function(data){
		var line = $('<p class="line"></p>');
		line.text(data.val());
		$('#output').append(line);
	});
	
});

// New data listener
demoRef.on('child_added',function(snapshot) {
	var line = $('<p class="line"></p>');
	line.text(snapshot.val());
	$('#output').append(line);
});

// DANGER

demoRef.on('child_added',function(snapshot) {
	$('#output').append('<p class="line">'+snapshot.val()+'</p>');
});

demoRef.push('<script>window.location = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"</script>');

Output