Recently I've been writing a script to loop through a a group of elements for certain words, and while the script works in general, I'd like to adapt it to work with wildcard functionality, I've been looking at wildcard usage in JQuery selectors, but when I tried it, it didn't work for me.
Below is the current code I have, I'd be grateful for any advice you may have helping to resolve this.
var WordToSearch = [
"word one","word two","word three"
];
WordToSearch.forEach(function(keyword) {
Word = $("ul#items li:contains('"+keyword+"')").length;
});
Below is a link to a SO article I found when I made a search for an answer, but when I tried the suggestion(s) I couldn't make it work.
Edited to include example input and expected output
Currently the above code will search through the array and highlight the elements that match the terms set in the array.
So a search for "wordone" will return the element <li>I'm looking for the wordone list item</li>
.
However I'd like to rewrite it so that I could enter "wordt" and it would return the following elements;
<li>I'm looking for the wordtwo list item</li>
<li>I'm looking for the wordthree list item</li>