Want to show/hide div based on dropdown box selection

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

    You need to either put your code at the end of the page or wrap it in a document ready call, otherwise you're trying to execute code on elements that don't yet exist. Also, you can reduce your code to:

    $('#purpose').on('change', function () {
        $("#business").css('display', (this.value == '1') ? 'block' : 'none');
    });
    

    jsFiddle example

提交回复
热议问题