Add List Item
Remove List Item

In the 5th lesson of the jQuery Crash-Course we learn how to add and remove elements dynamically.

The example for this lesson is adding and removing simple list items when clicking on the add or remove links.

$(function() {
	var i = $('li').size() + 1;
	
	$('a#add').click(function() {
		$('
  • ' + i + '
  • ').appendTo('ul'); i++; }); $('a#remove').click(function() { $('li:last').remove(); i--; }); });

    You can see all the code by viewing the source of this page (Ctrl-U in most browsers).



    Check out the video here.

    www.channeleaton.com