title: Filtering a tree view made of nested <ul> <li> along with child nodes
body: <p>Sorry for not entering the code I have worked on. I am explaining my doubt clearly this time. I have a tree made of nested ul and li tags. the tree node names are obtained from database. I need to filter the tree based on the name I enter in a text box. While showing the filtered tree item, if it the filtered item is a parent node, child nodes should also be listed(eventhough they don't match the text entered in texbox.)
    I have refered this link: <br> <a href="https://stackoverflow.com/questions/9375079/filter-multiple-ul-lists-with-jquery">Filter multiple &lt;ul&gt; lists with jQuery</a> <br></p>
  
  <p>This link helped me to filter out a tree node by entering its name in textbox. 
  But its childnodes are not visible.Please help me. Please find my code below:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function func(){
   alert("Onclick function parent node...");}
  
  function func1(){
   alert("Onclick function child node...");}</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
   $(document).ready(function() {
  
   $('input[type="text"]').keyup(function(){
  
      var filter = jQuery(this).val();
      jQuery("ul li").each(function () {
          if (jQuery(this).text().search(new RegExp(filter, "i")) &lt; 0) {
              jQuery(this).hide();
          } else {
              jQuery(this).show();
              jQuery(this).children().show();
          }
      });    
      });
  
  });
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
   &lt;input type="text" /&gt;
  
  &lt;ul class="mainlayer" id="category1"&gt;
      &lt;li class="layer1"&gt;&lt;a href="#" onclick="func();"&gt;item1&lt;/a&gt;
        &lt;ul&gt;
          &lt;li class="layer2"&gt;&lt;a href="#"  onclick="func1();"&gt;hju11&lt;/a&gt;&lt;/li&gt;
          &lt;li class="layer2"&gt;&lt;a&gt;kiu12&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li class="layer1"&gt;&lt;a&gt;item2&lt;/a&gt;&lt;/li&gt;
      &lt;li class="layer1"&gt;&lt;a&gt; item3&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thanks in advance. </p>