Want to show/hide div based on dropdown box selection

后端 未结 7 2187
感情败类
感情败类 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:21

    The core problem is the js errors:

    $('#purpose').on('change', function () {
        // if (this.value == '1'); { No semicolon and I used === instead of ==
        if (this.value === '1'){
            $("#business").show();
        } else {
            $("#business").hide();
        }
    });
    // }); remove
    

    http://jsfiddle.net/Bushwazi/2kGzZ/3/

    I had to clean up the html & js...I couldn't help myself.

    HTML:

    
    

    CSS:

    #business {
      display:none;
    }
    

    JS:

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

提交回复
热议问题