I am making some ajax request that returns the whole HTML page as the response. I need to grab some data from that page, in particular, value of specific <input>.
What is the best way to do that?
My ideas:
<body> tag ends and </body> starts, grab all stuff inside to string, and put via innerHTML to some container." character starts, read to buffer until new " come.It would be perfect if there is a framework that uses classic DOM syntax to do that, like:
htmlString.getElementById("someid").value
A pretty elegant solution is to use DOMParser.
const parser = new DOMParser()
const virtualDoc = parser.parseFromString(htmlString, 'text/html')
Then, treat virtualDoc like you'd treat any DOM-element,
virtualDoc.getElementById('someid').value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With