How to change the text of the OK button for Alert?

4

Personal I need an Alert with the "Confirm" button instead of the "OK" button. How do I do this?

    
asked by anonymous 27.03.2014 / 13:05

2 answers

6

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

For example, see the Dialog functionality of jQuery UI:

link

Considering that 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 legal too:

link

    
27.03.2014 / 13:20
2

Instead of alert use the confirm function, it returns true if the user confirms the action, however the button text of both functions can not be changed, it is relative to the browser used.

Another possible solution would be to create a custom alert with Javascript and CSS.

    
27.03.2014 / 13:07