Delegating Events Instead of Direct Binding in DOM

One thought on “Delegating Events Instead of Direct Binding in DOM”

  1. this would be more efficient —
    ;(function($){
    $(document).ready(function(){
    var $container = $(“div.container”), //use the div to find container to prevent jquery from searching all elements for class of container.
    buttons = 1; //cache this
    //event delegation
    $container
    .on(“click”,”button”,function(){
    alert(“Clicked”);
    })
    .on(“click”,”#addmore”, function(){
    $(“”).html(“Click Me ” + (++buttons)).appendTo($container);
    });
    });
    })(jQuery);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s