serach for a keyword jquery
// Search functionality
function myFunction() {
// Declare variables
var input = document.getElementById('myInput'),
filter = input.value,
ul = document.getElementById('myUL'),
lis = ul.getElementsByTagName('li'),
searchTerms = filter.match(/[a-z]+/gi),
re, index, li, a;
if (searchTerms) {
searchTerms = searchTerms.map(function(term) {
return '(?=.*' + term + ')';
});
re = new RegExp(searchTerms.join(''), 'i');
} else {
re = /./;
}
// Loop through all list items, and hide those who don't match the search query
for (index = 0; index < lis.length; index++) {
li = lis[index];
a = li.firstChild;
if (re.test(a.innerHTML + ' ' + a.getAttribute('data-keywords'))) {
li.style.display = '';
} else {
li.style.display = 'none';
}
}
}
Also in JavaScript:
- java script functions
- javascript atualize array
- javascript get elements that exist in two arrays
- play notification sound on chat js
- what are callbacks
- How do you select a particular option in a SELECT element in jQuery?
- clear value input jquery
- jquery number format comma
- installing jquery on window
- random int between two numbers javascript
- scroll to class jquery
- javascript loop last index
- adonisjs hook befor save
- atsby-plugin-tags npm
- change the border of an image js
- js random generator
- js object
- js map don't return
- js create element with class
- what are the two ways to create an array in javascript examples?
- javascript get browser name
- bootstrap set active tab javascript
- read file with deno
- string contains javascript