Want to show/hide div based on dropdown box selection

后端 未结 7 2186
感情败类
感情败类 2020-12-08 01:10

I want to have jQuery show div id=\'business\' only if \'business use\' is selected in the dropdown box.

This is my code:



        
7条回答
  •  长情又很酷
    2020-12-08 01:23

    Wrap the code within $(document).ready(function(){...........}); handler , also remove the ; after if

    $(document).ready(function(){
        $('#purpose').on('change', function() {
          if ( this.value == '1')
          //.....................^.......
          {
            $("#business").show();
          }
          else
          {
            $("#business").hide();
          }
        });
    });
    

    Fiddle Demo

提交回复
热议问题