title: Create a function to get selectors like jquery does with pure javascript
body: <p>I am tired of including jquery in simple projects but I am so used to using it and I am trying to break free form my dependency on it.  I am trying to create a function that will give the same feel of getting selectors like classes and tags.  Example: <code>$('selector').innerHTML = ".something";</code>.  I have just been looping through them one by one like so:</p>
  
  <pre><code>var classElements = document.querySelectorAll('.something');
  for (var i = classElements.length - 1; i &gt;= 0; i--) {
     classElements[i].innerHTML = "This Is A Div";
  } 
  </code></pre>
  
  <p>But I wanted to create a function where I could just loop through a selector without having to write out a for loop for everything that I want to find.  So I could just write it our like above <code>$('.something').innerHTML = "something";</code></p>
  
  <p>So far this is what I have but it will only get the first of each selector and won't get all of them.  Needless to say I am very stuck and the more I read on the subject the more confused I get.  I was wondering if someone could point me in the right direction where my thinking is flawed or explain how jquery goes about doing this.  Here is my code:</p>
  
  <pre><code>window.getElements = function(selector) {
      var selectors = document.querySelectorAll(selector);
      for (var i = selectors.length - 1; i &gt;= 0; i--) {
          var elements = selectors[i];
      }
      return elements;
  };
  
  getElements(".something").innerHTML = "something";
  </code></pre>
  
  <p>Here is a fiddle <a href="https://jsfiddle.net/wamosjk/y52f4wh8/" rel="nofollow noreferrer">Fiddle</a></p>