my html
<a href="/cart/?empty_cart=yes" title="Empty Bag">Empty cart</a>
i tried to add popup confirmation for .emptybutton in jQuery but ( ok or cancel ) have the same value , if i click cancel it won't abort
this is the jQuery i used
$(document).ready(function() {
$('.emptybutton').click(function() {
if (confirm('Are you sure?')) {
var url = $(this).attr('href');
$('#content').load(url);
}
});
});
i dont know were is my problem
thanks for any help
CodePudding user response:
Please try to do like this. You should prevent the a button click when you click cancel
button
$(document).ready(function() {
$('.emptybutton').click(function(e) {
if (confirm('Are you sure?')) {
var url = $(this).attr('href');
$('#content').load(url);
} else {
e.preventDefault();
}
});
});