how to show confirm box when clicking link (a href tag)?

I want to confirm user before deleting a row from the table so here the anchor tag html code, which i am using

<a href="/Mpa/Orders/DeleteQuote/22" class="btn btn-danger">Delete Quote</a>

Now, how to show confirmation dialog box("Are you sure, you want to delete it?") using javascript -jquery or HTML, before taking the action of delete or calling back end, if user clicks on above anchor tag?



Asked by:- manish
: 24976 At:- 9/28/2017 3:29:22 PM
html javascript jQuery confirmation-dialog javascript-events

5 Answers
profileImage Answered by:- Sam

You can call Confirmation box by simply add onclick event handler in a href(anchor ), so your code will be something like this

<a href="/Mpa/Orders/DeleteQuote/22" class="btn btn-danger" onclick="return confirm('Are you sure, you want to delete it?')">Delete Quote</a>

If user clicks on "OK" then only href="url" will be called.

Confirm Using SweetAlert

swal("Click on either the button or outside the modal.")
.then((value) => {
  swal(`The returned value is: ${value}`);

Fiddle link:

You need to include these CDN links

<script src=""></script>
<script src="" ></script>
At:- 9/29/2017 12:46:22 PM

profileImage Answered by:- vikas_jk

Here is the fiddle link answer's from the facebook group link

By Bogdan Suciu

By Nicholas Rios

both links work as expected, but the second answer(by Nicholas Rios) is preferred so here the code for it

    <tr><th>Row1 <a class="delete" href="#">Delete row</a></th></tr>
    <tr><td>Row2 <a class="delete" href="#">Delete row</a></td></tr>
    <tr><td>Row3 <a class="delete" href="#">Delete row</a></td></tr>


function addListeners(){
	var links = document.querySelectorAll('.delete');

	for(i = 0; i < links.length; i++){
		var currentLink = links[i];
	  currentLink.addEventListener('click', clickHandler);
function clickHandler(e){
  var elm =;
  var confirmation = confirm('Are you sure you want to delete this row?');
    return true;
  	return false;


At:- 9/29/2017 3:35:06 PM
above both answers works well, but i think, @Sam's answer is easy and simple :) 0
By : manish - at :- 10/3/2017 3:19:02 PM

profileImage Answered by:- vikas_jk

Another solution Using jQuery you can call confirm on anchor click like below

    return confirm('Are you sure want to continue?');
At:- 10/3/2018 2:01:14 PM

profileImage Answered by:- vikas_jk

If someone stumble upon this and looking for Bootstrap confirmation pop-up Modal before delete in asp .net MVC

Please take a look at recently added article related to this:


At:- 9/26/2019 9:29:46 AM

profileImage Answered by:- pika

Using Javascript to show Confirmation on click on all anchor links of page.

var anchorLink = document.getElementById('checkConfirmation');

    anchorLink.onclick = function() {
        var check = confirm("Are you sure you want to leave?");
        if (check == true) {
            return true;
        else {
            return false;

Considering HTML

<a href="" id="checkConfirmation">Navigate to other website</a>


It will ask the user before redirecting to the website.

At:- 9/2/2021 11:33:25 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use