title: document.getElementsByTagName:Cannot read property 'style' of undefined
body: <p>I wanna make a varible shortcut $$() so that i can use shortcut like $() [jquery] to save code in my project(ALL MY CODE IS PURE JAVASCRIPT).
  when i put the string of id or class, it works all right, but when i put the tagName, it shows  Cannot read property 'style' of undefined, it seems that the code is right,help,thanks</p>
  
  <p>One more, is that way to defined a shortcut variable $$() to use in pure javascript environment right way? or is there any best practice to define a global variable like this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    window.onload = function(){
   function $$(ele){
     var pattern1 = /#/g;
     var pattern2 = /\./g;
     var pattern3 = /!/g;
          var matches = ele.match(/[^#\.!]/g);//array
          var elementS = matches.join("");
  
          //alert(matches+elementS);
           // console.log(document.getElementsByTagName(elementS));
          
          var spaceExist = /\s/.test(elementS)
     if(pattern1.test(ele)){
      return document.getElementById(elementS);
                
     }else if(pattern2.test(ele)){
      //console.log(elementS);
      return document.getElementsByClassName(elementS);
  
     }else if(pattern3.test(ele)){
      alert('hi');
      console.log(elementS);
      return document.getElementsByTagName(elementS);
     }else if(spaceExist){
      return document.querySelectorAll(elementS);
     }
    }
    $$('#hme').style.backgroundColor = 'red';
    $$('.myp')[0].style.backgroundColor = 'green';
    $$('!h2')[0].style.display = 'none';//this not work,shows Cannot read property 'setAttribute' of undefined
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;h1 id="hme"&gt;hi,friend&lt;/h1&gt;
   &lt;p class="myp"&gt;mmdfdfd&lt;/p&gt;
   &lt;h2&gt;hhhhhh&lt;/h2&gt;</code></pre>
  </div>
  </div>
  </p>