jeudi 13 décembre 2018

Else Statement not firing in Jquery

I am trying to just a simple if / else statement in Jquery, but the else statement is not catching. All it is displaying a class when an item is selected and when that is not selected it hides. Instead once the item is deselected the div doesn't hide. Not sure what the case is

$(document).ready(function() {
   $('#__stateInputSection__').change(function() {
      if ($("#__stateInputSection__ option:selected").text() === "CA - CALIFORNIA ") {
       console.log($("#__stateInputSection__ option:selected").text());

       $.cookie("State", "CA", {
        expires: 7,
        path: '/'
       });

       $($(".propnote")[0]).append("<div class='prop65'><div align='center' 
        style = 'border: 1px solid black; padding: 10px; font-size: 1em; max-width: 
        600 px; margin: 0 auto;
        '><a href='#
        '><img style='
        width: 25 px;
        ' 
        src = 'https://files.admin.newmarkethealth.com/images/Warning-icon-hi.png' / >
        <
        b > WARNING: < /b></a > California Proposition 65 < /div></div > ");


        $('.prop65').click(function(e) {
         console.log();
         e.preventDefault();
         $('#prop65overlay').show();
         $('#faded-background').show();
         console.log("catch");
        });

       }
       else {

        $(".prop65").css("display", "none");
        $.cookie("State", "CA", {
         expires: 0,
         path: '/'
        });
       };
      });

So the else statement at the bottom is not firing at all.

Aucun commentaire:

Enregistrer un commentaire