title: HTML Include Javascript
body: <p>Can anyone please help me to understand why my javascript code is not working when I'm including the HTML file in other HTML, whereas I'm able to include HTML code and the javascript is working on the file in which it is written?</p>
  <p>Codes:
  Initial HTML File:</p>
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;img src="http://localhost/Website/Static/Logo.png" id="logo"&gt;
  &lt;h1 hidden id="name"&gt;SAM&lt;/h1&gt;
  &lt;script&gt;
    document.getElementById('logo').addEventListener('error', function() {
      this.hidden = true;
      document.getElementById('name').hidden = false;
    })
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>HTML file which is importing initial file the code:</p>
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="http://localhost/Website/script3.js"&gt;&lt;/script&gt;
  &lt;div sam-include='http://localhost/Website/Components/brand.htm'&gt;&lt;/div&gt;
  &lt;!--&lt;div id="search"&gt;&lt;/div&gt;--&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>And, the code for static attribute:</p>
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>document.addEventListener('DOMContentLoaded', function(params) {
    var x = document.querySelectorAll("[sam-include]");
    for (var i = 0; i &lt; x.length; i++) {
      var SAM_Request = new XMLHttpRequest();
      var temp = x[i];
      SAM_Request.onreadystatechange = function() {
        if (this.readyState == 4 &amp;&amp; this.status == 200)
          temp.innerHTML += this.responseText;
      };
      SAM_Request.open('GET', temp.getAttribute('sam-include'), true);
      SAM_Request.send();
    }
  });</code></pre>
  </div>
  </div>
  </p>