appendTo makes HTML code not to work correctly

appendTo makes HTML code not to work correctly

Hi,
I'm trying to add some HTML code inside a div using appendTo. The HTML code is added and I can see it in the screen, the problem is that I can't "close" the div using the link... but I can "close" the div when the HTML code is loaded in the page (when the HTML is in the website). This is my code:

  1. jQuery(function(){
  2. jQuery('.showWindow').click(function(){
  3. var id = $(this).attr('target');
  4. $( "<div id='"+id+"' class='window'><div class='window-bar'><div class='window-title'>"+id+"</div><div class='window-tabber'><span class='minimize'><a target='"+id+"' class='minimize'>_</a></span><span class='close'><a target='"+id+"' class='closel'>X</a></span></div></div><div class='window-content'></div></div>" ).hide().appendTo( "#screen" ).fadeIn(999);
  5. $('#'+$(this).attr('target')).draggable({ containment: "#screen", scroll: false, handle: ".window-bar" });
  6. $('#'+$(this).attr('target')).resizable({containment: "#screen", minHeight: 200, minWidth: 400});
  7. $('#'+$(this).attr('target')).position({
  8. of: $('#'+$(this).attr('target')).parent(),my: 'right top',at: 'right top',
  9. });
  10. $('#'+$(this).attr('target')).offset({ top: 60, left: 30 });
  11. });
  12. jQuery('.closel').click(function(){
  13. $('#'+$(this).attr('target')).fadeOut('slow', function(){$(this).remove()});
  14. });
  15. });
I know that jQuery already has a window extension/plug-in but I'm trying to build one myself to learn how to use jQuery.

Thanks