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.
- Return to blog post
- Download and follow on GitHub
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;
});
Welcome to 1999. Look at me go!!