Does not work when pressing a certain sequence of buttons, with js and html

0

Good morning guys over stack. I'm going through a strange problem, I do not know how to describe it.

Basically I have the 2 screens down

I'mcreatingaform,whereitwillbenecessarytoregisterandeditit.Somyideawastocreate3buttons,onetoedit,ortoregisterandanothertocancel.

<divclass="col-md-12">
        <a href="javascript:;" id="EdicaoLocalidade" class="btn green EditarLocalidade">Editar Localidade</a>
        <a href="javascript:;" id="CadastrarLocalidade" class="btn green CadastrarLocalidade">Cadastrar Localidade</a>
        <a href="javascript:;" class="btn default Cancelar">Cancelar</a>                            </div>

The idea is, when you press the New Location button, it is to make the Edit button disappear, thus getting only the Register and Cancel.

$('.page-toolbara').click(function(){inicNovaLocalidade();$('.portlet.NovaLocalidade').slideDown();$(this).addClass('disabled');$(".EditarLocalidade").css("display","none");

        });

The same idea would be to edit it, when you click on the pen, next to the data, that is, to edit.

$(".Editar").on('click', function () {
            $('.portlet.NovaLocalidade').slideDown();
            $(".CadastrarLocalidade").css("display","none");

        })

The bizarre problem is when I first press the Edit button, the cancel button does not work at all, but if I press the New Location button, cancel it works fine for both cases.

My idea is that when I press Cancel, the slide down will undo the hidden effect of the button.

//evento click do cancelar
$('#CadastroLocalidade a.Cancelar').click(function() {
    //teste para o botão cadastrar localidade
    var editLocalidade = document.getElementById("EdicaoLocalidade");
    var cadLocalidade = document.getElementById("CadastrarLocalidade");

    if(editLocalidade.style.display != 'none'){
        $('.portlet.NovaLocalidade').slideUp();
        $('.page-toolbar a').removeClass('disabled');
        $(".EditarLocalidade").css("display","inline-block");
    }


});

UPDATING

When I click on this button here, canceling does not work ... this is not the error at all

    
asked by anonymous 25.01.2017 / 12:53

2 answers

0

In this function, clicking on register will perform a hide on the edit button and vice versa. Clicking cancel will display all the buttons again.

$("#operacao").on('click','a', function () {
    if($(this).attr("id") == "editar"){
        $("#cadastrar").hide();
        $("#editar").show();
    }else if($(this).attr("id") == "cadastrar"){
    	$("#cadastrar").show();
        $("#editar").hide();
    }else{
    	$("#cadastrar").show();
        $("#editar").show();
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="operacao">
    <a href="#?" id="editar">Editar</a>
    </br>
    <a href="#?" id="cadastrar">Cadastrar</a>
    </br>
    <a href="#?" id="cancelar">Cancelar</a> 
</div>
    
25.01.2017 / 16:54
0
$('#CadastroLocalidade a.Cancelar').click(function() {

The element ID is wrong #CadastroLocation should be #Added r Location

    
25.01.2017 / 17:11