Advertisement
kotvalera83

search js

Jan 23rd, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.92 KB | None | 0 0
  1. <input id="inp">
  2. <div id='parent'>
  3.    <div>
  4.       <div>abc</div>
  5.       <div>a</div>
  6.       <div>b</div>
  7.    </div>
  8.    <div>
  9.       <div>c</div>
  10.       <div>d</div>
  11.    </div>
  12. </div>
  13. <script>
  14. window.onload = function() {
  15. //onload begin
  16.    var inp = document.getElementById('inp');
  17.   var find = function() {
  18. //find begin
  19.     var parent = document.getElementById('parent');
  20.     var divs = parent.getElementsByTagName('div');
  21.     len = divs.length;
  22.     for (var i = 0; i < len; i++) {
  23. //for begin
  24.       re='.*?';
  25. p = new RegExp(re+inp.value,["i"]);
  26. m = p.exec(divs[i].innerHTML);
  27.      if (divs[i].childNodes.length == 1 && m == null && inp.value != '') {
  28.        divs[i].style.display = 'none';
  29.      } else if (divs[i].style.display != 'block') {
  30.        divs[i].style.display = 'block';
  31.      }
  32.    }
  33. //for end        
  34.  }
  35. //find end
  36.  inp.onkeyup = function() {
  37.    find();
  38.  }
  39. }
  40. //onload end
  41. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement