title: document.createElement is not working for anchor tags
body: <p>I was trying to validate some URLs. I have tried using regex and JavaScript URL constructors as well. But I was specifically trying to solve the task with <code>document.createElement('a')</code>.
  I am following the codes for the task and it works fine in <strong>JSbin</strong>. But not working in my local editor. Can anyone explain if <code>document.createElement('a')</code> is valid for anchor tags and why there is a result in JSbin and not in my local editor(it shows some error).</p>
  <p>P.S Working new with JavaSCript and DOM Manipulation</p>
  <p><strong>HTML</strong></p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
    &lt;title&gt;test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id=&quot;div&quot;&gt;&lt;/div&gt;
  &lt;script src=&quot;test.js&quot;&gt;&lt;/script
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><strong>JavaScript</strong></p>
  <pre><code>function isValidURL(str) {
     var div = document.getElementById('div');
     var a  = document.createElement('a');
     a.href = str;
     a.innerText = &quot;check&quot;;
     div.appendChild(a);
     return a.protocol === &quot;http:&quot; || a.protocol === &quot;https:&quot;;
  }
  console.log(isValidURL('file:///Y:/bleh/index.html'));
  console.log(isValidURL('https://www.youtube.com/watch?v=iFP-EWO_Q_o'));
  console.log(isValidURL('en.wikipedia.org'));
  </code></pre>
  <p>The console results <em>false</em>, <em>true</em>, <em>true</em> accordingly in <em>jsbin</em>. But show error <code>ReferenceError: document is not defined</code> in local editor.</p>