javascript – How to change the text of the Alert OK button?

Question:

I need an Alert with the "Confirm" button instead of the "OK" button. how do I do that?

Answer:

One option is to use a plugin that builds a custom confirmation window. The advantage is that you can style it with the colors and text you want. The downside is having to use one more plugin in your code.

For example, see jQuery UI's Dialog functionality:

http://jqueryui.com/dialog/#modal-confirmation

Assuming the jQuery UI is installed, the code looks like this:

Javascript:

$(function() {
  $( "#dialog-confirm" ).dialog({
    resizable: false,
    height:140,
    modal: true,
    buttons: {
      "Remover todos os itens?": function() {
        $( this ).dialog( "close" );
      },
      Cancel: function() {
        $( this ).dialog( "close" );
      }
    }
  });
});

HTML:

<div id="dialog-confirm" title="Empty the recycle bin?">
  <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Todos os itens serão removidos. Deseja continuar?</p>
</div>

PS: If you want something more "modern", this option is also nice:

http://fabien-d.github.io/alertify.js/

Scroll to Top