JSFiddle - React, Tailwind, and code Playground
by thesystemrestart
HTML
<input type="text" id="search" />
<ul id="workflow_books">
<li>
<h6 class="custom"> Custom Books</h6>
<ul>
<li class="custom-books">
<a>Don't see your book in our list? Add it yourself!</a>
</li>
</ul>
</li>
<li>
<h6>Academic</h6>
<ul>
<li>
<a>Academic Book One</a>
</li>
<li>
<a>Academic Book Two</a>
</li>
</ul>
</li>
<li>
<h6>Botany</h6>
<ul>
<li>
<a>Botany Book One</a>
</li>
<li>
<a>Botany Book Two</a>
</li>
</ul>
</li>
</ul>
JavaScript
var $products = $('#workflow_books li ul:not(:first)');
$("#search").keyup(function() {
var val = this.value.trim();
if (!val) $('li:hidden', '#workflow_books').show();
else {
$('li:hidden', $products).show();
$('li', $products).filter(function() {
var re = new RegExp(val, 'ig');
return !re.test($('a', this).text());
}).hide();
$products.each(function() {
if ($('li:visible', this).length == 0) $(this).parent('li').hide();
else $(this).parent('li').show();
});
}
});