Get element by xpath on HTML string

I have a JS variable that contains an a string that represents an HTML page. For example:

var response = "<!DOCTYPE html><html><body><h1>This is heading 1</h1></body></html>"

I’d like to perform query selectors and xpath evaluations on this response to traverse through the HTML elements. Since the response is not in the DOM I can’t use document.x actions.

One option is to write it into an invisible iframe in the DOM but this is not allowed for Chrome extensions. Are there any other alternatives?

38 thoughts on “Get element by xpath on HTML string”

  1. 795735 169596Hello. excellent job. I did not imagine this. This is a fantastic story. Thanks! You produced certain fine points there. I did a search on the subject matter and located the majority of folks will have the same opinion with your blog. 880013

    Reply

Leave a Comment