Category Covered

Javascript function not working without alert

I have a javascript function but without alert why its not working? I am confused. I used the delay/ sleep function but still now no success.

 

$(document).ready(function(){
   $.get('xml/categories.xml',function(data){
    var _html="<ul>";
     $(data).find('Categories').each(function(key,value){
         _html+="<li><a href='#'>"+$(this).find('CategoryName').text()+"</a>";
         _html+=genTree($(this).find("CategoryID").text());
        //console.log($(this).find("CategoryID").text());
          _html+="</li>";
      })
      _html+="</ul>";
      $(".treeview-red").html(_html);
     
    });
    function genTree(_cat_id)
    {
      var ht="";
    
     $.get('xml/products.xml',function(pdata){
      ht+="<ul>";
       $(pdata).find('Products').each(function(){
        if(_cat_id==$(this).find('CategoryID').text())
        {
         ht+="<li><a href='#' class='"+$(this).find('QuantityPerUnit').text()+"' class='"+$(this).find('QuantityPerUnit').text()+"'>"+$(this).find('ProductName').text()+"</a></li>";
         //alert(ht);
        }
       })
	   
       ht+="</ul>";
      });
      alert('Test mode');
	  //console.log(ht);
      
     return (ht);
    }
    
  });