Last active
December 12, 2015 04:28
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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