Live Query: Unordered List Examples (Using Anonymous Functions)

A common use-case is when a new list item is added to an unordered list and a script notified of the change.

Get notified when a list item is added

The list below uses a Live Query to call a function when a new list item is added. This function adds the following text to each list item: '(Updated)' and removes it when the Live Query is expired.

var matched = function() {
	$(this)
		.append('<small>&nbsp;(Updated)</small>');
};
var unmatched = function() {
	$('small', this)
		.remove();
};
$('#example1-2', 'body')
	.find('li')
		.livequery(matched, unmatched);