I took some code from the internet that searches data entered in a table (contains query) but i want it to look if text appears at the beginning of the word. here is the code
function filter(selector, query) {
query = $.trim(query); //trim white space
query = query.replace(/ /gi, '|'); //add OR for regex
$(selector).each(function() {
($(this).text().search(new RegExp(query, "i")) < 0) ? $(this).hide().removeClass('visible') : $(this).show().addClass('visible');
});
}
how can i change it to look for query at beginning of the word rather than anywhere in the word
thanks
Use
query = "^" + query.replace(/ /gi, '|');