title: jQuery append() not working properly, only second time
body: <p>I'm trying to append HTMl content into a div after gathering data through a PHP script that returns a JSON array. I successfully parsed the data returned into a string var with all the content i need, but it wont work on the first time. Checked vars with firebug and all loading and parsing ok. Can anyone help?
  Heres a sample of the full code:
  The first function loads the data from php script...</p>
  
  <pre><code>function LoadProds(idf){
  if (idf){
      request = '../controllers/returnprods.php?idfamilia='+idf;
  
      $.getJSON(request,function(data){
      if (!data.resultado){
      nProds = data.length;
  
      for (i = 0; i &lt; nProds; i++){
          htmlContent = '&lt;div class="cartigo"&gt;\n &lt;div class="cartigodetalhe"&gt;';
          h1Content = ' &lt;h1&gt;'+data[i].nome+'&lt;/h1&gt;'
          h2Content = '&lt;h2&gt;'+data[i].preco+'€&lt;/h2&gt; \n&lt;/div&gt;'
          imgContent = '&lt;img src="images/products/'+data[i].fullpath+'" width="183px"    height="87px"&gt; \n &lt;/div&gt;';
  
          divproduto = htmlContent+h1Content+h2Content+imgContent;
          sProdutos = sProdutos + divproduto;
      }
      ncurrPos = 0;
  }
  }); 
  
  }else{
  return "(empty)";
  }
  }
  </code></pre>
  
  <p>The second, uses the click() event to load the parsed data and changes the look</p>
  
  <pre><code>$(".cbotaogrande").click(function(){
  activeid = "#"+$('img[src$=".png"]').attr("id");
  if (activeid){
      activeimg = $(activeid).attr("src");
      activeimg = activeimg.substr(0,activeimg.length - 7)+".jpg";
      $(activeid).attr("src", activeimg);
  }
  activebtn = $(this).attr("id");
  activebtn ="#img"+activebtn.substr(4);
  tmpsource = $(activebtn).attr("src");
  $(activebtn).attr("src",tmpsource.substr(0,tmpsource.length-4)+"_on.png");
  
  activebtn = "cgradiente"+activebtn.substr(4);
  
  $(".cbotoestopo").attr("id",activebtn);
  $(".clogo").attr("id",activebtn);
  
  LoadProds($(this).attr("comment")); // Calls the load data function above...
  
  
  $(".cartigo").remove();  // Remove divs existentes com produtos
  if (sProdutos != ''){
      $("#cprodutos").append(sProdutos); 
      sProdutos = '';
  }else{
      sProdutos = '';
  }
  
  });
  </code></pre>
  
  <p>Hope you can help me. 
  Thanks in advance</p>