Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>How about this?</p> <p>The html part is changed for testing purpose:</p> <pre><code>&lt;input id="my-input"/&gt; &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;p&gt;This is something wonderful&lt;/p&gt;&lt;/li&gt; &lt;li id="li-1-2" class="li"&gt;&lt;span&gt;Try is out&lt;/span&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;a href="javascript: void(0)"&gt;This needs to be selected&lt;/a&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;No that wonderful&lt;/li&gt; &lt;li id="li-3-2" class="li"&gt;How is this?&lt;/li&gt; &lt;li id="li-3-3" class="li"&gt;Need to match&lt;/li&gt; &lt;li id="li-3-4" class="li"&gt;No need to match?&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The jQuery/JavaScript</p> <p>$("document").ready(function() {</p> <pre><code>$('#my-input').keyup(function(e) { e.stopImmediatePropagation(); var keycode = (e.keyCode ? e.keyCode : e.which); if (keycode == 13) { //Do something } else { var matchText = $('#my-input').val(); if (matchText.length &gt;= 3) { var selectedLists = new Array(); var flagArray = new Array(); var i = 0; $(matchText.split(/\s+/)).each(function() { var textToMatch = $(this)[0]; if (textToMatch &amp;&amp; textToMatch != "") { $("li").each(function() { if ($(this).html().match(eval("/" + textToMatch + "/ig"))) { if (!flagArray[$(this).attr("id")]) { selectedLists[i++] = $(this).attr("id"); //For your implementation, I suggest that you store the object, rather than the id so that you can clone it without an iteration flagArray[$(this).attr("id")] = true; } } }); } }); if (selectedLists.length &gt; 0) { alert(selectedLists); } } } }); </code></pre> <p>});</p>
 

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