As JScript is the 'out of browser', Microsoft ES3 variant of Javascript, it's hard to do something simple as parsing a HTML string into an object.
As mentioned, JScript does reside not in a browser, so it does not have the standard document type, nor does it have the domparser.
I can make a document object as so:
var document = new ActiveXObject('htmlfile')
document.innerHTML = http.responseText
and while this will render the html response into a document, I cannot use getElementsByClassName, TagName or even ID - which is exactly what I need to do with the html responses I'm looking at (a mix of those mentioned).
I've tried using John Resig's "pure javascript HTML parser", but that won't run in ES3 and I am not versed enough in JScript/ES3 to understand why not.
https://johnresig.com/blog/pure-javascript-html-parser/
Ultimately, I want to parse the HTML file in a document object, and be able to pull elements by their class, id, tagname etc. For me it sounds like this should be easy, but it isn't.
Any help would be appreciated.
getElementById
and getElementsByTagName
seem to work:
var document = new ActiveXObject('htmlfile');
document.open();
document.write('<html><div id="div1" class="class1">test</div></html>');
document.close();
WScript.Echo(document.getElementById("div1").id);
WScript.Echo(document.getElementsByTagName("div")[0].id);
WScript.Echo(document.getElementsByTagName("div")[0].className);