This is more of a statement and wondering if anyone has experienced this than a question, but here goes. Consider the following code using JQuery:
<input type="submit"
value="Delete"
onclick="return doesUserConfirmDelete();" />
<script type="text/javascript">
function doesUserConfirmDelete()
{
return confirm("Do you really want to delete this entry?\n\n" +
"Click \'OK\' to delete this entry;\n\n" +
"otherwise, click \'Cancel.\'");
}
var delBtn = $('input[value="Delete"]');
console.info(delBtn[0]);
delBtn.removeAttr('onclick');
// attempted adding the following, but nothing changed:
delBtn.removeProp('onclick');
delBtn.prop('onclick', null);
delBtn[0].onclick = null;
// end attempts for naught
delBtn.off('click');
delBtn.click();
</script>
When I run the above code in Chrome, the things that happen, in order, are:
- Confirm box is shown (even though the
onclick
was supposedly removed) - I click cancel
console.info
message prints to console.
What is going on here? How do I remove the click events from the button and click it so that there's no confirmation dialog?