bind vs live vs delegate

bind vs live vs delegate

by bhupendra negi

HTML

<ul id="members" data-role="listview" data-filter="true" data-mini="true">
    
    <li>
        <a href="detail.html?id=10">
            <h3>SHYAM</h3>
            <p><strong>jQuery Core Lead</strong></p>
            <p>Boston, United States</p>
        </a>
    </li>
     <li>
        <a href="detail.html?id=10">
            <h3>John Resig</h3>
            <p><strong>jQuery Core Lead</strong></p>
            <p>Boston, United States</p>
        </a>
    </li>
     <li>
        <a href="detail.html?id=10">
            <h3>RAM</h3>
            <p><strong>jQuery Core Lead</strong></p>
            <p>Boston, United States</p>
        </a>
    </li>
    
</ul>

JavaScript

// BIND 
/*
$("#members li a").bind("click", function(e) { e.preventDefault();
                                              alert("BIND METHOD");
                                             });


// live this method deperected after jquery 1.7
$("#members li a").live("click", function(e) { e.preventDefault();
                                              alert("LIVE METHOD");
                                             });
*/
//delegate 

$("#members").delegate("li a", "click", function (e) {
    e.preventDefault();
    alert("delegate clicked");

});

// ON CAN  BE USED INSTEAD OF BIND