I'm facing an issue in jquery. So, i just registered here. I need your help guys.
I'm using keyup function for matching ul li string. As per i type, the listitems scroll down/up to the specific text located li. But the issue is that when li has double text like
- Air balloon
- Balloon
then contains function stops on the Air balloon. Whereas i want the result which is having only Balloon text.
Basically i want that the search should perform from the very first letter.
Here is my code :
<ul>
<li data-id="a">Air balloons</li>
<li data-id="b">Balloons</li>
<li data-id="l">List Items</li>
<li data-id="i">Items</li>
</ul>
$(function(){
$('input#search').keyup(function (e) {
var searchValue = $(this).val();
jQuery.expr[':'].contains = function (a, i, m) {
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
var containText = $('li:contains(' + searchValue + ')');
var id = containText.attr('data-id');
alert(id);
});
});
updating with jsfiddle