title: Changing Javascript methods "createElement", "appendChild", "setAttribute" to Jquery
body: <p>I'm having hard times when I try change javascript method createElement, appendChild, setAttribute to Jquery. I got function called "showThumbnail" which shows a thumbnail of newly uploaded img. I have to change it's javascript code to JQuery. It's easy when I have to replace "getElementById" method but the stairs begin when I dealing with "createElement" and when I try to add attributes to new object, innerHTML and its parents. 
  Here is showThumbnail function</p>
  
  <pre><code>function showThumbnail(files) {
      var file = files[0]
  
      //var thumbnail = document.getElementById("thumbnail");
      var $thumbnail = $('#thumbnail').get(0);
  
      var pDiv = document.createElement("div");
      var image = document.createElement("img");
      var div = document.createElement("div");
  
  
      pDiv.setAttribute('class', 'pDiv');
      $thumbnail.appendChild(pDiv);
  
  
      image.setAttribute('class', 'imgThumbnail');
      pDiv.appendChild(image)
  
      div.innerHTML = "X";
      div.setAttribute('class', 'closeDiv');
      pDiv.appendChild(div)
  
      image.file = file;
      var reader = new FileReader()
      reader.onload = (function (aImg) {
          return function (e) {
              aImg.src = e.target.result;
          };
      }(image))
      var ret = reader.readAsDataURL(file);
      var canvas = document.createElement("canvas");
      ctx = canvas.getContext("2d");
      image.onload = function () {
          ctx.drawImage(image, 100, 100);
      }
  }
  </code></pre>
  
  <p>This is how it work in JFIDDLE: <a href="http://jsfiddle.net/r0taz01L/6/" rel="nofollow">http://jsfiddle.net/r0taz01L/6/</a> </p>
  
  <p>I was thinking about this</p>
  
  <pre><code>var $image = $("&lt;img&gt;", { class: "imgThumbnail" });
  var $pDiv = $("&lt;div&gt;", { class: "pDiv" });        
  var $div = $("&lt;div&gt;", { class: "closeDiv" });
  
  $thumbnail.append($pDiv);
  $pDiv.append($image);
  $pDiv.append($div);
  </code></pre>
  
  <p>What do You think?</p>