var InputSort = $('input#sort'); var minlen = 2; InputSort.bind('keyup',function(){ if(InputSort.val().length>=minlen) { dosearch(); } }); function dosearch() { var term = InputSort.val(); $('.light').each(function(){ $(this).after($(this).html()).remove(); }); t = ''; $('.sorting li').each(function(){ $(this).html($(this).html().replace(new RegExp(term, 'ig'), '<span class="light">$&</span>')); }); }; ul {padding: 5px;} li {list-style: none; color: #333;} .light {color: #f00;} <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> <input type="text" placeholder="Поиск" id="sort"> <ul class="sorting"> <li>Яблоко</li> <li>Апельсин</li> <li>Лимон</li> <li>Дыня</li> <li>Арбуз</li> </ul> At the moment, this code is looking for matches in words and selects them.
How to realize that the selection will go to <li> ?