0
function getSourceAsDOM(url) {
  xmlhttp=new XMLHttpRequest();
  xmlhttp.open("GET",url,false);
  xmlhttp.send();
  parser=new DOMParser();
  return parser.parseFromString(xmlhttp.responseText,"text/html");      
}

I use this function to get the html of a web page via link.

I want to search it for a specific div. how do i do it?

I tried element.querySelectorAll('.nameOfClass') but i get NodeList[] with 0 elements.

if I console.log() it i get #document

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • https://stackoverflow.com/questions/30040319/how-to-execute-document-queryselectorall-on-a-text-string-without-inserting-it-i – epascarello Feb 03 '21 at 18:37
  • 3
    FYI: making a synchronous requests is not the best thing to do. – epascarello Feb 03 '21 at 18:37
  • `getSourceAsDOM('yoururl'`).querySelectorAll('.nameOfClass')` does not return anything? – mplungjan Feb 03 '21 at 18:39
  • If the MIME type returned by the server is "text/html", `xmlhttp.response` is a `Document`. It requires the use of asynchronous HTTP and setting the `responseType` correctly. See [HTML in XMLHttpRequest at MDN](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/HTML_in_XMLHttpRequest) – Heretic Monkey Feb 03 '21 at 18:46

0 Answers0