querySelectorAll() to html from another page

ajax, html, javascript, selectors-api

Solution

You could create new document and put `responseText` into it. Then you can use `querySelectorAll()`. Here is your `onreadystatechange` function:

function () {
    if (xml.readyState == 4) {
        var container = document.implementation.createHTMLDocument().documentElement;
        container.innerHTML = xml.responseText;
        var nodeList = container.querySelectorAll('selector');
    }
}

Problem

Good morning, I am geting html of another page by AJAX: ``` var xml = new XMLHttpRequest() xml.onreadystatechange = function () { if (xml.readyState == 4) { // here I need to work with data // xml.responseText } } xml.open("GET", url, false); xml.send(null) ``` How I can apply querySelectorAll() to html content of another page?

Original source