Can't focus input when jquery confirm onClose event

95 views Asked by At

I need to focus node when onClose event. but always focused clicked button.

        $.alert({
            title: 'title',
            content: 'message,
            onClose : function () {
                $('input[name="title"]').focus();
            }
        });
1

There are 1 answers

0
4b0 On

By default jQuery-confirm keeps track of the last focused element when it is opened, and when it is closed, it returns the last focused element to focus.

So work around for that:

Example:

$.alert({
  title: 'title',
  content: 'message',
  onClose: function() {
    this._lastFocused = $('input[name="title"]');
    // this will notify jquery-confirm to focus the  element when it close.
  }
});