Last active
August 29, 2015 14:13
-
-
Save johnmurch/738334b3d3902e5327ed to your computer and use it in GitHub Desktop.
JavaScript Confirm Modal using Bootstrap 3
This file contains hidden or 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
$(document).ready(function() { | |
$('a[data-confirm]').click(function(ev) { | |
var href = $(this).attr('href'); | |
if (!$('#dataConfirmModal').length) { | |
$('body').append('<div id="dataConfirmModal" class="modal fade" role="dialog" tabindex="-1" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="dataConfirmLabel">Please Confirm</h3></div><div class="modal-body"></div><div class="modal-footer"><button class="btn" style="margin-top:10px;" data-dismiss="modal" aria-hidden="true">Cancel</button><a class="btn btn-danger" id="dataConfirmOK">YES</a></div></div></div></div>'); | |
} | |
$('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm')); | |
$('#dataConfirmOK').attr('href', href); | |
$('#dataConfirmModal').modal({show:true}); | |
return false; | |
}); | |
}); |
This file contains hidden or 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
<a href="/remove" data-confirm="Are you sure you want to do that?" class="btn btn-danger btn-xs">Remove</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment