Disable modal window button using Jquery

0

I have a modal window with a button, and I would like that, when I pressed the button (a tag), it would be disabled and I would like to "Wait ..."

See my code:

//#idDivModal4 -> modal
//.btn-enviar-lembrete -> tag a (botão)

 $('#idDivModal4').on('click', '.btn-enviar-lembrete', function(){   
 event.preventDefault();     

     $(this).prop("disabled",true);
     $(this).prop("value","Aguarde.."); 

});

Modal:

...
 <a class="btn btn-danger btn-enviar-lembrete">Enviar lembrete</a>

However, it is not working. What am I doing wrong?

    
asked by anonymous 10.01.2017 / 15:08

3 answers

1

To create a button you do not necessarily need to put it inside a <a href... tag, you can simply create it with

<button class="btn-enviar-lembrete">Enviar</button>

The javascript will look like this;

$('.btn-enviar-lembrete').on('click', function() {
    $(this).prop({
        disabled: true,
        innerHTML: 'Aguarde...'
  });
});

But if you prefer you can also put a link tag around;

<a href="">
    <button class="btn-enviar-lembrete">
       Enviar
    </button>
</a>

Remember that a tags have a default behavior that is "reload page", so to prevent this link from doing its padrão function, add the event parameter within function and then tell jquery to "prevent default behavior".

$('.btn-enviar-lembrete').on('click', function(event) {
    event.preventDefault();
    $(this).prop({
        disabled: true,
        innerHTML: 'Aguarde...'
  });
});

See working in JsFiddle

    
10.01.2017 / 15:53
0

$ (". # btn-send-reminder")

Remove the dot before the # because it is either a class or an id.

btn-send-reminder = id

.btn-send-reminder = class

Check beforehand because the jquery event is in class and the action inside the event is with id and with the period before the id.

    
10.01.2017 / 15:16
0

Edited:

 $('#idDivModal4 #btn-enviar-lembrete').click(function() {
       $(this).prop("disabled",true);
       $(this).prop("value","Aguarde.."); 
 });

or how is your code

  $('#idDivModal4').on('click', '#btn-enviar-lembrete', function(){   
  event.preventDefault();     

 $("#btn-enviar-lembrete").attr("disabled", true);
 $("#btn-enviar-lembrete").attr('value', 'Aguarde...');

In addition you have a confusion between the. it's the # O "." - > equals class "#" to id of objects

    
10.01.2017 / 15:17