1

I have a jQuery animate function which I want to call if the selectedvalue for my dropdown list is X

       <script>
    $(function () {
        var state = true;
        ($("#button").click)(function () {
            if (state) {
                $("#effect").animate({
                    backgroundColor: "#aa0000",
                    color: "#fff",
                    width: 500
                }, 1000);
                  } else {
                $("#effect").animate({
                    backgroundColor: "#fff",
                    color: "#000",
                    width:500

                }, 1000);
            }
            state = !state;
        });
    });
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Rahat Saini
  • 311
  • 1
  • 4
  • 15

2 Answers2

0

Your can try like this

jQuery(document).ready(function(){
    var state = true;
  $("#otherCatches").change(function() {
      if (state) {
            $("#effect").animate({
                backgroundColor: "#aa0000",
                color: "#fff",
                width: 500
            }, 1000);
              } else {
            $("#effect").animate({
                backgroundColor: "#fff",
                color: "#000",
                width:500

            }, 1000);
        }
        state = !state;

   });
});
शेखर
  • 17,412
  • 13
  • 61
  • 117
0

DropDown id -> ddlDropDown

      $(document).ready(function(){
          var state = true;
        $("#ddlDropDown").change(function() {
             if ($("#ddlDropDown").val()=="X") { //Checking if value is X
                $("#effect").animate({
                     backgroundColor: "#aa0000",
                     color: "#fff",
                     width: 500
                  }, 1000);
              } else {
               $("#effect").animate({
               backgroundColor: "#fff",
               color: "#000",
               width:500

        }, 1000);
      }
      state = !state;
  });
});
G . R
  • 543
  • 1
  • 6
  • 12