display block is not working on jQuery

Asked

Viewed 53 times

0

I got the following jQuery script:

    $.ajax({
        url: "_scripts/_php/_validacoes/cadastrarCelulaMembro.php",
        type: "POST",
        dataType: "json",
        data: {   
             idPastor : $("#idPastor").val(),
             idRede : $("#idRede").val(),
             idRegiao : $("#idRegiao").val(),
             idArea : $("#idArea").val(),
             idSetor : $("#idSetor").val(),
             idCelula : $("#idCelula").val(),
             idMembro : $("#idMembro").val()
        },
        beforeSend: function() {
            $("#buttonCadastrarCelulaMembro").attr('display','none');
            $("#imgCarregando").attr('display','block');
        },
        success: function (result) {
            $("#buttonCadastrarCelulaMembro").attr('display','block');
            $("#imgCarregando").attr('display','none');
            if (result[0] == "Erro")
                $(".resposta").html(result[1]);
            else
                $(".resposta").html(result[1]);
        }
    });
  }

The idea is to enter the $.ajax and before sending the form, give a display: none in the button and a display: block in a image of Loader

beforeSend: function() {
    $("#buttonCadastrarCelulaMembro").attr('display','none');
    $("#imgCarregando").attr('display','block');
},

And, after receiving the return of PHP, do the reverse process.

success: function (result) {
                $("#buttonCadastrarCelulaMembro").attr('display','block');
                $("#imgCarregando").attr('display','none');
...

But this is not happening.

Where am I going wrong?

This is the end of the form:

...

    <button id="buttonCadastrarCelulaMembro" class="button">Cadastrar Membro na Célula</button>
    <img id="imgCarregando" style="display: none" src="_imgs/carregando.gif" />
    <br />
<div class="resposta"></div>
</div> 
<div class="dadosMembro"></div>

Buuton class CSS

.button {
    width: 250px;
    height: 30px;
    margin: 3px;
}

2 answers

2

Change attr for css. Thus remaining:

$("#buttonCadastrarCelulaMembro").css('display','none');
$("#imgCarregando").css('display','block');
  • I forgot that css is not attribute but style. In this case, it has to be . css() , not . actribute() or . prop().

-1

I forgot that css is not attribute and yes style.

In case, it has to be

.css() 

and not

.actribute() 

or

.prop()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.