JSFiddle - React, Tailwind, and code Playground
HTML
<div class="menu">
<div id="contain" ><ul id="navlist">
<form id="live-search" action="" class="styled" method="post">
<fieldset>
<input type="text" class="text-input" id="filter" value="" />
<span id="filter-count"></span>
</fieldset>
</form><br/><br/>
<li><a class="menu" href="#" id="show" name="heada"><h3> Section 1</h3></a>
<div class="slider" style="display:block; display:none;">
<a class="menu-item" href="#">Section 1 - Item 1</a>
<a class="menu-item" href="#">Section 1 - Item 2</a>
<a class="menu-item" href="#">Section 1 - Item 3</a>
<a class="menu-item" href="#">Test</a>
</div>
</li>
<li><a class="menu" href="#" id="show" name="heada"><h3> Section 2</h3></a>
<div class="slider" style="display:block; display:none;">
<a class="menu-item" href="#">Section 2 - Item 1</a>
<a class="menu-item" href="#">Section 2 - Item 2</a>
<a class="menu-item" href="#">Section 2 - Item 3</a>
</div>
</li>
<li><a class="menu" href="#" id="show" name="heada"><h3> Section 3</h3></a>
<div class="slider" style="display:block; display:none;">
<a class="menu-item" href="#">Section 3 - Item 1</a>
<a class="menu-item" href="#">Section 3 - Item 2</a>
<a class="menu-item" href="#">Section 3 - Item 3</a>
</div>
</li>
</ul></div></div>
CSS
.slider {color:black; width:200px; border: 1px solid #000; min-height:10px; }
JavaScript
$(document).ready(function () {
$('.slider').hide(800);
$('a#show').on('click', function (e) {
var filter = $(this).val(), count = 0;
e.preventDefault();
var elem = $(this).next('.slider')
$('.slider').not(elem).hide();
elem.toggle();
});
$("#filter").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(), count = 0;
if(filter.length > 0)
{
$(".menu-item").css("display","none");
// Loop through the comment list
$(".menu-item").each(function(){
if ($(this).text().search(new RegExp(filter, "i")) > -1)
{
$(this).show().closest(".slider").show();
count++;
}
});
}
else
{
$('.slider').hide();
}
// Update the count
var numberItems = count;
//$("#filter-count").text("Number of Comments = "+count);
});
});