Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// BAD: 1000 event listeners for 1000 rows $(".table tbody tr").on("click", handler); // GOOD: 1 listener on the table body via delegation $(".table tbody").on("click", "tr", handler); // Also handles dynamically added rows: $(".list").on("click", ".item", function() { $(this).toggleClass("selected"); }); // Remove all delegated handlers when cleaning up: $(".list").off("click", ".item");
Result
Open