title: Set source of image of dynamically created element in JavaScript
body: <p>I am trying to get the id of the dynamically created element in <code>JavaScript</code> to set <strong>src</strong> as:</p>
  
  <pre><code>$scope.source = canvas.toDataURL();
  let htmlString = "&lt;img id='imageId' style='height: 100px; width: 100px;'&gt;";
  let doc = document.createElement('div');
  doc.innerHTML = htmlString;
  let image = doc.getElementById('imageId');
  image.src = $scope.source;
  </code></pre>
  
  <p>But I always get image as <strong>undefined</strong>, because there is not method getElementById in <strong>doc</strong>. </p>
  
  <p>How do I set the image source in this?</p>