Function to parse an HTML string. Returns a queryable element or fragment.
npm install parsehtml
var parseHTML = require('parsehtml');
var htmlSnippet = '<div><a>first</a></div> <div class="x"><a>second</a></div> <div><a>third</a></div>',
html = parseHTML(htmlSnippet);
console.log(html.querySelector('.x'));
//=> <div class="x"><a>second</a></div>