title: How to filter elements in vanilla Javascript like in jQuery?
body: <p>For example, in jQuery, if i want all <code>&lt;div&gt;</code> and <code>&lt;p&gt;</code> elements, I do this:</p>
  
  <pre><code>var $x = $("p, div");
  </code></pre>
  
  <p>And then if i want all the <code>&lt;div&gt;</code> elements in x, then I do this:</p>
  
  <pre><code>var $divs = $x.filter("div");
  </code></pre>
  
  <p>So how do i do this simple <code>filter</code> thing in vanilla JavaScript?</p>
  
  <p>For example, to select all <code>&lt;div&gt;</code> and <code>&lt;p&gt;</code>, then I can do this: </p>
  
  <pre><code>var x = document.querySelectorAll("div, p");
  </code></pre>
  
  <p>But vanilla JavaScript doesn't have the filter function like in jQuery, so I can't do this:</p>
  
  <pre><code>var divs = x.filter("div"); // ERROR
  </code></pre>
  
  <p>Hope someone can help me with this :-)</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Some comments/answers have suggested to do something like <strong>.tagName == "DIV"</strong> to find the divs, however, i want a solution with a string selector like in jQuery.</p>
  
  <p>The reason is because i also want to filter with attributes, classes and even multiple selectors where you put in comma. And the string selector must be dynamic.</p>
  
  <p>That means, i dont know whats in the selector. It could be "div[foo='asd'], .bar" or "#hello, [xx='yy'], p"</p>
  
  <p>So  i cant just hardcode the .tagName == "DIV", beacuse i dont know whats in the selector string.</p>