Show/Hide multiple DIVs with Select using jQuery

前端 未结 4 1708
孤城傲影
孤城傲影 2020-12-15 11:49

I essentially have the same situation as the person in the following question:

Link: how to show/hide divs by select.(jquery)

Through extensive searching wit

4条回答
  •  误落风尘
    2020-12-15 12:26

    This code is a little more succinct:

    $(document).ready
    (
      function()
      {
        $("div.box").hide();
        $("#dropdown").change
        (
          function()
          {
            var selectedValue = $(this).val();
            if(selectedValue !== "0")
            {
              $("div.box").show();
              $("#div" + selectedValue).hide();
            }   
          }   
        );
      }
    };
    

    Essentially, if there is a value selected (i.e., the option is not set to "Choose"), then all div.box elements are shown. The DIV matching the selected option is then hidden. This should happen quickly enough so that the flash is not noticeable.

提交回复
热议问题