riklomas / quicksearch

A jQuery plugin for searching through tables, lists, etc quickly
http://www.lomalogue.com/jquery/quicksearch/
680 stars 261 forks source link

How to include another element into the quicksearch? #82

Open q2apro opened 6 years ago

q2apro commented 6 years ago

Let's assume we have something like:

<h2>Fruit</h2>
<ul>
    <li>Apple</li>
    <li>Pear</li>
    <li>Orange</li>
</ul>

<h2>Veggy</h2>
<ul>
    <li>Cucumber</li>
    <li>Tomato</li>
    <li>Minions</li>
</ul>

I'd use quicksearch on an input field like this (just example code including highlighting):

    // search
    $("input#search").quicksearch("ul li", {
        noResults: '#noresults',
        stripeRows: ['odd', 'even'],
        loader: 'span.loading',
        onBefore: function() { $("ul li").unhighlight(); }, // remove former highlighting
        onAfter: function() {
            if($('#id_search').val()!='' && $('#id_search').val().length>1) {
                $("ul li:visible").highlight( $('#search').val() );
            }
        },
    });

Question is: How can I include the h2 into the quicksearch?

The quicksearch only reads the li elements.

nitriques commented 6 years ago

$("input#search").quicksearch("ul li, h2", ... should do the trick ?