How to show/hide div when we select 'all' option

show/hide div based on select option value jquery
show/hide div based on multiple dropdown selection
show hide div based on dropdown selection
show/hide dropdown option javascript
hide selected value from dropdownlist javascript
jquery hide select option not working
display content based on dropdown selection
show/hide div based on dropdown selection angular 4

I have a small requirement. I need to show and hide divs based on the option selected. Below is my code. Ho to show all green and red class div's when I select 'all' option. It works for red and green options. Thanks in advance.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="colorselector">
            <option>Choose Color</option>
            <option value="all">All</option>
    		<option value="red">Red</option>
            <option value="green">Green</option>
    </select>
    <div class="red box">You have selected <strong>red option</strong> so i am here</div>
    <div class="green box">You have selected <strong>green option</strong> so i am here</div>


<script type="text/javascript">
$(function() {
  $('#colorselector').change(function(){
    $('.box').hide();
    $('.' + $(this).val()).show();
	
  });
});
</script>


    .box{
        color: #fff;
        display: none;
        margin-top: 20px;
    }
    .red{ background: #ff0000; }
    .green{ background: #228B22; }

Since you'll only have one "all" option, you can do an "if" to check if that option was pressed:

$(function() {
  $('#colorselector').change(function(){
    if($(this).val()=="all"){
      $('.box').show();
    }else{
      $('.box').hide();
      $('.' + $(this).val()).show();
    }
  });
});

Show Hide DIV Based on Dropdown Selection in jQuery, How do you show a hidden TextBox when a specific option is selected? The following example will demonstrate you how to show and hide div elements based on the dropdown selection or selected option in a select box using the jQuery change () method in combination with the show () and hide () methods. The div boxes in this example are hidden by default using the CSS display property which value is set to none.


Try this code:

<select id="colorselector">
            <option>Choose Color</option>
            <option value="all">All</option>
            <option value="red">Red</option>
            <option value="green">Green</option>
    </select>
    <div class="red box">You have selected <strong>red option</strong> so i am here</div>
    <div class="green box">You have selected <strong>green option</strong> so i am here</div>

Script:

<script type="text/javascript">
$(function() {
 $('#colorselector').on('change', function() {
  var data = $(this).val();
 if( data =='red')
 {
  $('.green').hide();
  $('.red').show();
 }
 else if($(this).val() =='green')
 {
  $('.green').show();
  $('.red').hide();
 }
 else
 {
  $('.green').show();
  $('.red').show();
 }
});
});
</script>

How to show a hidden text-box when a specific option is selected , an element are with the visibility style attribute and the display style attribute. In order to show the div we will need to add a Javascript function. We will pass the ID attribute of the Div to the function. Basically this means that we can use this one function to show or hide more than one Div on the same page. Below is the Javascript code that we will add the the Head section of the page.


Use an if statement to detect if the user is selecting 'all'. Please check the below code.

$(function() {
  $('#colorselector').change(function(){

    $('.box').hide();

    //if user is selecting 'all', show all boxes
    if($(this).val() == 'all'){

        $('.box').show()

    //otherwise only show the color they select
    } else {

      $('.' + $(this).val()).show();

    }


  });
});

Here is a working JS Fiddle Example

How to: Hidden Select Box in HTML, How do you hide form field based on dropdown choice? Show Hide DIV with TextBox based on DropDownList Selected Value (Selection) using jQuery The HTML Markup consists of a HTML SELECT DropDownList and an HTML DIV consisting of a TextBox. The DropDownList has been assigned a jQuery OnChange event handler.


Hide and Show fields based on selection from drop down box , The following example will demonstrate you how to show and hide div elements based on the dropdown selection or selected option in a select box using the  Slow equates to 600 milliseconds and fast to 200. By the way, hide ( ) simultaneously changes the height, width, and opacity of the element it’s working on. Take a jQuery UI course to master the language. Hide ( ) also supports a callback function that gets fired when the animation is finished.


javascript show hidden div when select option is selected, So what I want, I have a drop down list (select with a number of options). When a certain option is selected I want a hidden div to display. <select id="test"  As you click on the button “Show/Hide” if the div element was visible it will be hidden and vice versa. See online demo and code In the click event of the button, I placed jQuery toggle method which is attached to a div element with id: toggle_tst .


Want to show/hide div based on dropdown box selection, I want to have jQuery show div id='business' only if 'business use' is selected in the dropdown box. This is my code: <script src="http://ajax. Login Form Signup Form Checkout Form Contact Form Social Login Form Register Form Form with Icons Newsletter Stacked Form Responsive Form Popup Form Inline Form Clear Input Field Hide Number Arrows Copy Text to Clipboard Animated Search Search Button Fullscreen Search Input Field in Navbar Login Form in Navbar Custom Checkbox/Radio Custom Select Toggle Switch Check Checkbox Detect Caps Lock Trigger Button on Enter Password Validation Toggle Password Visibility Multiple Step Form Autocomplete