Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- searchBox = document.querySelector("#search-box");
- contracts = document.querySelector(".examples");
- var when = "keyup";
- searchBox.addEventListener("keyup", function (e)
- {
- //declare variables
- var text = e.target.value;
- var options = contracts.querySelectorAll('.item>a');
- //loop through all examples to find a match
- for(var i = 0; i < options.length; i++)
- {
- var option = options[i];
- var optionText = option.text;
- var lowerOptionText = optionText.toLowerCase();
- var lowerText = text.toLowerCase();
- var regex = new RegExp("^" + text, "i");
- var match = optionText.match(regex);
- var contains = lowerOptionText.indexOf(lowerText) != -1;
- //hide all content that doesn't match
- if(match || contains && text !== '')
- {
- option.style.display = 'block';
- }
- else
- {
- option.style.display = 'none';
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement