Event Delegation Demo
| ISBN | Title | Media | Price | Inventory | Favorite |
|---|---|---|---|---|---|
| 978-0-470-45733-7 | DotNetNuke and Web Standards | eBook | $6.99 | -1 |
|
| 978-0-470-43870-1 | Professional DotNetNuke 5 | Paperback | $49.99 | 55 |
|
| 978-0-470-46257-7 | DotNetNuke 5 User's Guide | Paperback | $49.99 | 10 |
|
| 978-0-470-17116-5 | Professional DotNetNuke Module Programming | Paperback | $49.99 | 5000 |
|
JavaScript Source
jQuery(function() {
$("tbody#delegate").mouseover(function(event) {
mouseHandlerDelegate(event)
})
.mouseout(function(event) {
mouseHandlerDelegate(event)
})
.each(function() {
showFavIcon($(this));
});
$("img.fav").click(function() {
var row = $(this).closest("tr");
row.toggleClass("favorite");
showFavIcon(row);
});
});
function mouseHandlerDelegate(event) {
switch (event.target.tagName.toLowerCase()) {
case "td":
$(event.target).closest("tr").toggleClass("highlight");
break;
case "tr":
$(event.target).toggleClass("highlight");
break;
}
}
function showFavIcon(row) {
var icon = (row.hasClass("favorite")) ?
"/images/checked.png" :
"/images/unchecked.png";
$("img", row).attr("src", icon);
}