Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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';
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js nvl function 
Javascript :: load a script after a button is pressed js 
Javascript :: mdn 
Javascript :: chroma js 
Javascript :: array con tridimensional javascript 
Javascript :: how to bind a json output result to any new model 
Javascript :: how to manage the key press and blur with input id in vue js 
Javascript :: como arreglar el error de Linking.openUrl no funciona react native 
Javascript :: puppeteer print page numbers after second page 
Javascript :: jsdom nodelist empty array why 
Javascript :: every character on your keyboard js 
Javascript :: survey js type: "rating", 
Javascript :: svlete each index 
Javascript :: jquery selector immediate child 
Javascript :: javascript kommentare 
Javascript :: altenrive for react native 
Javascript :: dateFormat 
Javascript :: show selected text in textarea && activeElement 
Javascript :: js fix for rtl langages 
Javascript :: compbineReducers from redux 
Javascript :: Read data in props.histroy.push in react component 
Javascript :: Insert a custom object 
Javascript :: event pooling in react/event.persist/using async function in event callback 
Javascript :: 8.1.3. Varying Data Types¶ Arrays 
Javascript :: javascript substtgin 
Javascript :: express js jump to above directory 
Javascript :: 10.8.1.2. The isPalindrome Function 
Javascript :: invoke method inside class javascript 
Javascript :: js painting app 
Javascript :: locale data angular 12 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =