jQuery select change show/hide div event

前端 未结 9 1485
失恋的感觉
失恋的感觉 2020-11-27 17:34

I am trying to create a form which when the select element \'parcel\' is selected it will show a div but when it is not selected I would like to hide the div. Here is my mar

9条回答
  •  野性不改
    2020-11-27 18:28

    I used the following jQuery-based snippet to have a select-element show a div-element that has an id that matches the value of the option-element while hiding the divs that do not match. Not sure that it's the best way, but it is a way.

    $('#sectionChooser').change(function(){
        var myID = $(this).val();
        $('.panel').each(function(){
            myID === $(this).attr('id') ? $(this).show() : $(this).hide();
        });
    });
    .panel {display: none;}
    #one {display: block;}
    
    
    

    Thing One

    Thing Two

    Thing Three

提交回复
热议问题