erichynds

« Return to Blog Post

jQuery "create" Event Demo

This new event duck punches $.fn.domManip and $.fn.html to fire a custom "create" event when new, matching elements are inserted into the DOM.

Code for this demo:

$.fn.geocities(function(){
   /* 
      code to make a div look friggin sweet.
      wraps text in marquee and applies a 
      beautiful color scheme.
   */
});

// apply plugin to all current div.geocities
$("div.geocities").geocities();

// apply plugin to all future div.geocities
$("div.geocities").live("create", function(e){
	$(this).text("I am a new element!").geocities();
});

// the "create another" link
$("#create-new-div").click(function(){
	$("div.geocities:last").after('<div class="geocities"></div>');
	return false;
});

Create another

Welcome to 1999. Look at me go!!