Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove focus from button after closing javascript confirm box

I have a button with a bootstrap element on it.

<button title="delete" type="button"  class="btn btn-default btn-sr"  data-confirm="Are you sure to delete this item?"><span class="glyphicon glyphicon-trash white"></span></button></a>';

It has a css property which I color it red.

When user clicks the delete button, a JavaScript confirmation will come out.

The problem is whenever i click cancel, the button will be focused. How do I remove the focused button?

Here is the jQuery code:

<script>
    $(document).on('click', ':not(form)[data-confirm]', function(e) {
        if( !confirm($(this).data('confirm')) ) {
            e.stopImmediatePropagation();
            e.preventDefault();
        }
    });
</script>
like image 613
KingJ Avatar asked Sep 07 '25 14:09

KingJ


2 Answers

Maybe could you try to blur() the button?

<script>
    $(document).on('click', ':not(form)[data-confirm]', function(e) {
        if( !confirm($(this).data('confirm')) ) {
            e.stopImmediatePropagation();
            e.preventDefault();
            $(this).blur(); // to make the focus disappear
        }
    });
</script>
like image 164
D4V1D Avatar answered Sep 09 '25 10:09

D4V1D


$(this).blur();

over

document.activeElement.blur()
like image 42
Xanlantos Avatar answered Sep 09 '25 08:09

Xanlantos