Advertisement
meetsos

Show-Hide based on Select Option jQuery

Sep 4th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.97 KB | None | 0 0
  1. <style>
  2. .colorz {
  3.   padding: 2em;
  4.   color: #fff;
  5.   display: none;
  6. }
  7. .redcolor {
  8.   background: #c04;
  9. }
  10. .yellowcolor {
  11.   color: #000;
  12.   background: #f5e000;
  13. }
  14. .bluecolor {
  15.   background: #079;
  16. }
  17. </style>
  18.  
  19. <div>
  20.   <select id="colorselector">
  21.      <option value="...">...</option>
  22.      <option value="redcolor">Red</option>
  23.      <option value="yellowcolor">Yellow</option>
  24.      <option value="bluecolor">Blue</option>
  25.   </select>
  26. </div>
  27.  
  28. <div class="output">
  29.   <div id="redcolor" class="colorz redcolor">  “Good artists copy, great artists steal” Pablo Picasso</div>
  30.   <div id="yellowcolor" class="colorz yellowcolor"> “Art is the lie that enables us to realize the truth” Pablo Picasso</div>
  31.   <div id="bluecolor" class="colorz bluecolor"> “If I don't have red, I use blue” Pablo Picasso</div>
  32. </div>
  33.  
  34. <script>
  35. $(function() {
  36.   $('#colorselector').change(function(){
  37.     $('.colorz').hide();
  38.     $('#' + $(this).val()).show();
  39.   });
  40. });
  41. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement