Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Last active December 12, 2015 04:28
Show Gist options
  • Save simonewebdesign/4714082 to your computer and use it in GitHub Desktop.
Save simonewebdesign/4714082 to your computer and use it in GitHub Desktop.
Display a confirm box when the user clicks on the delete link (event delegation).
/* Display a confirm box when the user
* clicks on the delete link.
*/
function confirmDeleteHandler(e) {
e = e || window.event;
var target;
target = e.target || e.srcElement;
if ( target.className.match(/\bconfirmDelete\b/) ) {
if (!confirm('Are you sure?')) {
e.preventDefault();
}
}
}
if (document.body.addEventListener) {
document.body.addEventListener('click', confirmDeleteHandler, false);
} else {
document.body.attachEvent('onclick', confirmDeleteHandler); // for IE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment