I try to search with an input field a list of items,
<ul class="display">
<li title="Pizza Otto">some divs</li>
<li title="Pizza Prono">some divs</li>
<li title="Pizza David">some divs</li>
</ul>
The code below works fine for words in the <li>...</li> I want to put there some divs and to add a title attribute to <li> where to make the search.
$('input[name="q"]').search('.display li', function(on) {
on.all(function(results) {
var size = results ? results.size() : 0
$('#count').text(size + ' results');
});
Any idea for the right selector here: .search('.display li'? Or where I have to make the changes?
Thanks and sorry for my English…
P.S. Is my first question here!
UPDATE: function to test if the val is contained
function query(selector) {
if (val = this.val()) {
return $(selector + ':contains("' + val + '")');;
} else {
return false;
}
}
I’m not familiar with the search method… but
would select the li you’re looking for
I think @robin-pyon was thinking of the :contains() selector, the .contains() method actually searches for a dom element inside of another dom element, if the text you want to search is contained in the LI you can use this to select the ui: