Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input id="inp">
- <div id='parent'>
- <div>
- <div>abc</div>
- <div>a</div>
- <div>b</div>
- </div>
- <div>
- <div>c</div>
- <div>d</div>
- </div>
- </div>
- <script>
- window.onload = function() {
- //onload begin
- var inp = document.getElementById('inp');
- var find = function() {
- //find begin
- var parent = document.getElementById('parent');
- var divs = parent.getElementsByTagName('div');
- len = divs.length;
- for (var i = 0; i < len; i++) {
- //for begin
- re='.*?';
- p = new RegExp(re+inp.value,["i"]);
- m = p.exec(divs[i].innerHTML);
- if (divs[i].childNodes.length == 1 && m == null && inp.value != '') {
- divs[i].style.display = 'none';
- } else if (divs[i].style.display != 'block') {
- divs[i].style.display = 'block';
- }
- }
- //for end
- }
- //find end
- inp.onkeyup = function() {
- find();
- }
- }
- //onload end
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement