user3228565 user3228565 - 26 days ago 5
jQuery Question

jquery update content using user text input text

good day, I have this html:

<div class="subcategory_name_wrapper" id="categories">

<div class="subcategory_name">
<a href="#1">apple
</a>
</div>
<div class="subcategory_name">
<a href="#2">plum
</a>
</div>
<div class="subcategory_name">
<a href="#3">cherry
</a>
</div>
</div>


I want to filter the subcategories using jquery and an text input, when the use types, the content is updated (filtered) as per his input. for example if he types cherry, only that div is sh

Answer

try this

$('#input').on('change',function(e){
var searchValue=this.value;
var selector='a:contains("'+searchValue+'")';
var $allDivParents = $('.subcategory_name');
$allDivParents .hide();
var $validDivsParents =  $(selector).parent();
$validDivsParents.show();
})
Comments