Error showing and hiding a div with Jquery

Asked

Viewed 82 times

1

Gentlemen, good morning, gentlemen! I’m trying to show and hide an image if it satisfies the established conditions, but they only appear after Isis, not understanding what I’m missing. That is, the div cancel1, cancel2 and cancel3 are not showing up when the if is met.

<script type="text/javascript">
    $(document).ready(function(){
    var valor_mo_contrato_s = parseFloat($("#valor_mo_contrato").val()).toFixed(2);
    var valor_mobra_s = parseFloat($("#total_mobra_orc_calc").val()).toFixed(2);
    var valor_mat_contrato_s = parseFloat($("#valor_mat_contrato").val()).toFixed(2);
    var total_mat_orc_calc_s = parseFloat($("#total_mat_orc_calc").val()).toFixed(2);
    var valor_unitario_contrato_s = parseFloat($("#valor_unitario_contrato").val()).toFixed(2);
    var total_unitario_orc_calc_s = parseFloat($("#total_unitario_orc_calc").val()).toFixed(2);

    if (parseFloat(valor_mo_contrato_s) < parseFloat(valor_mobra_s)) {
        $("#valor_mo_orc_check").text("O Sistema sugere que o Fiscal verifique o valor de Mao de Obra.");
        $("#valor_mo_orc_check").css({"color": "red"});
        $("#cancel1").css('display','block');
    }else{
        $("#ok1").css('display','block');
    };

    if (parseFloat(valor_mat_contrato_s) < parseFloat(total_mat_orc_calc_s)) {
        $("#valor_mat_orc_check").text("O Sistema sugere que o Fiscal verifique o valor de Material.");
        $("#valor_mat_orc_check").css({"color": "red"});
        $("cancel2").css('display','block');
    }else{
        $("#ok2").css('display','block');
    };

    if (parseFloat(valor_unitario_contrato_s) < parseFloat(total_unitario_orc_calc_s)) {
        $("#valor_unitario_orc_check").text("Orcamento REPROVADO pelo SISTEMA, de acordo com os limites contratuais.");
        $("#valor_unitario_orc_check").css({"color": "red"});
        $("#cancel3").css('display','block');
    }else{
        $("#ok3").css('display','block');
    };
});
</script>
  • In addition to the problems pointed out below, you have already confirmed that the conditions of the ifwere they true? A console.log('qualquer msg') inside the if can help you.

2 answers

2

It seems we missed the " : "between display and block.
Try it this way:

$("#cancel1").css('display':'block');
$("#cancel2").css('display':'block');
$("#cancel3").css('display':'block');

*Note that in your cellCancel 2 is without the '#' identifier also generating error in the code.

  • +1 pro .show() and .hide()

  • I used both forms but without success. I made the modifications with the keys and used . Hide

0


In jquery Voce you can use the function hide() to hide and show() to show, try using this to see if it solves.

  • The problem was in the way I was trying to do, the div was inside a table, when I took it worked.!

Browser other questions tagged

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