After reading this question's answer
I was wondering how to structure a preventDefault / stopPropagation that depends on a user click event, for example:
<html>
<a data-handler="add_to_cart" data-item_id="5">Click</a>
</html>
Clicking the element currently calls the backend (by ajax) to add item 5 to the user cart. But what if I want to inject a dialog first (javascript only)
var template = '' +
'<div class="dialog">' +
'<p>Really add this item?</p>' +
'<button>Yes</button>' +
'<button>No</button>' +
'</div>'
$(a).click(function(){
# open the dialog template
# if the correct button is clicked continue the default event
});
I do not want to use confirm
or prompt
, I am basically looking for a way to implement their functionality with my own html dialog.