Advertisement
Guest User

TheMrNiceGuy Dynamic Div Removal Tutorial

a guest
Nov 19th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.35 KB | None | 0 0
  1. <!--TheMrNiceGuy Dynamic Search Tutorial-->
  2. <!DOCTYPE=html>
  3. <html>
  4. <head>
  5. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">//this enables JQuery</script>
  6. <style type="text/css">
  7. .container
  8. {
  9. width: 100%;
  10. }
  11.  
  12. .container_of_hc
  13. {
  14. border: solid 3px #B30015;
  15. height: 100px;
  16. }
  17.  
  18. .horizontal_containers
  19. {
  20. font-size: 45px;
  21. text-align: center;
  22. width: 75%;
  23. float: left;
  24. }
  25.  
  26. .color
  27. {
  28. float: right;
  29. text-align: center;
  30. width: 20%;
  31. height:25%;
  32. font-size:12px;
  33. }
  34. </style>
  35. <title>TheMrNiceGuy Dynamic Search Tutorial</title>
  36. </head>
  37. <body>
  38.  
  39. <div>
  40.     <div class="search_bar">
  41.         <form><!--The Field from which to gather data-->
  42.             <input id="searchfield" onclick="value=''" value="Case Sensitive Search">
  43.         </form>
  44.         <script>//This is the script for showing and hiding.
  45.             $("#searchfield").keyup(function() {
  46.                 var str = $("#searchfield").val();  //get current value of id=searchfield
  47.                 if (str.length == 0)                //if searchfield is empty, show all
  48.                 {
  49.                     $(".horizontal_containers").show();
  50.                 }
  51.                 else                //if input contains matching string, show div
  52.                 {                   //if input does not contain matching string, hide div
  53.                 $("div:contains('" + str + "').horizontal_containers").show();
  54.                 $("div:not(:contains('" + str + "')).horizontal_containers").hide();
  55.                 }
  56.                 /*
  57.                 if (str.length == 0)                //if searchfield is empty, show all
  58.                 {
  59.                     $(".container .color").show();
  60.                 }
  61.                 else                //if input contains matching string, show div
  62.                 {                   //if input does not contain matching string, hide div
  63.                     $(".container div:contains('" + str + "').color").show();
  64.                     $(".container div:not(:contains('" + str + "')).color").hide();
  65.                 }*/
  66.             });
  67.         </script>
  68.     </div>
  69. </div>
  70. <!--Containers With Text-->
  71. <div class="container">
  72.     <div class="container_of_hc">
  73.         <div class="horizontal_containers">Cat</div>
  74.         <div class="color">Black</div>
  75.         <div class="color">White</div>
  76.         <div class="color">Orange</div>
  77.     </div>
  78.     <div class="horizontal_containers">Dog</div>
  79.     <div class="horizontal_containers">Rat</div>
  80.     <div class="horizontal_containers">Zebra</div>
  81.     <div class="horizontal_containers">Wolf</div>
  82.     <div class="horizontal_containers">Monkey</div>
  83.     <div class="horizontal_containers">Bear</div>
  84.     <div class="horizontal_containers">Ostrich</div>
  85. </div>
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement