The code will search for element inside the collapsible div. For search the keypress event will search the data in collapsible using jquery. If the term is found, only that collapsible tree chain should be shown, others should be hidden.
$(document).ready(function(){
$("#searchbox").keypress(function(){
$("div.collapse").collapse("hide"); //this will reset the div to hidden so that only search term is displayed
var search = $("#searchbox").val();
$("div.collapse").find(":contains("+search+")").parent().collapse("show");
});
});
JSFiddle link: https://jsfiddle.net/zvn1bsxd/
The problem is, the search is working only for odd keyup events. When you type 2nd time/ 4th time and so on, all the div are hidden. I am having trouble to determine why this is happening.