JSFiddle - React, Tailwind, and code Playground

JavaScript

var parser = new DOMParser(),
    str = "<!DOCTYPE html><html><head><title>Test</title></head><body><div id='div1'>asdf</div></body></html>",
    doc = parser.parseFromString(str, "application/xml");

console.log(doc.getElementById("div1").textContent);