Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do a case insensitive search for text within elements using jQuery
    primarykey
    data
    text
    <p>I have the following basic layout:</p> <pre><code>&lt;div id="container"&gt; &lt;div id="div-a"&gt; &lt;ul id="ul-1"&gt; &lt;li id="li-1-1" class="li"&gt;&lt;/li&gt; &lt;li id="li-1-2" class="li"&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="div-b"&gt; &lt;ul id="ul-2"&gt; &lt;li id="li-2-2" class="li"&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="div-c"&gt; &lt;ul id="ul-3"&gt; &lt;li id="li-3-1" class="li"&gt;&lt;/li&gt; &lt;li id="li-3-2" class="li"&gt;&lt;/li&gt; &lt;li id="li-3-3" class="li"&gt;&lt;/li&gt; &lt;li id="li-3-4" class="li"&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>What I'm trying to do is, when an input field gets typed into, it initiates a search of the <code>&lt;li&gt;</code> elements. It does a <strong>case insensitive</strong> search on all text contained within the <code>&lt;li&gt;</code> elements. The <code>&lt;li&gt;</code> element will contain html such as images links paragraphs etc. When a match is found it returns the <code>&lt;li&gt;</code> ids e.g. <code>li-1-1,li-2-1</code> etc (whatever is best practice). All this is happening while I type. I plan to get the id's and clone the <code>&lt;li&gt;</code>. But that shouldn't be important at this stage.</p> <p>So far I have the following:</p> <pre><code>$('#my-input').keyup(function(e) { e.stopImmediatePropagation(); var keycode = ( e.keyCode ? e.keyCode : e.which ); if( keycode == 13 ) { //Do something } else { if( $('#my-input').val().length &gt;= 3 ) { //code goes here } } )} </code></pre> <p>What is the best way to go about this. I have looked at contains, filter, looping over all <code>.li</code> elements in various ways etc and had no luck so far. Any help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload