I'm trying to figure how I can do a partial match base on input given by user. Cross check that value inside the input within the array for any partial matches, then add a class display
For example if I type inside the inputbox the following:
Build Web Application John James
It will fetch all the values inside for any partial matches inside the array. Then loop through all the name classes to add a class called display. If there isn't a single match it will then remove the class display
$(".task-label input").on("change keyup paste", function(){
let handles = ['john', 'jake', 'james'];
for(let elements of handles ) {
if (elements.includes($('.task-label input').value())) {
$('.name-'+ elements).addClass();
} else {
console.log('no match');
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="task-label">
<input id="name" type="text" name="name">
</div>
<ul class="name-list">
<li id="john" class="name name-john">@John</li>
<li id="jake" class="name name-jake">@Jake</li>
<li id="alex" class="name name-alex">@Alex</li>
<li id="allison" class="name name-allison">@Allison</li>
</ul>