0

I am writing an extension that makes several server request to grab html. I need to parse the html to serialize the form values contained in the html. Some of the html returned contains js that dynamically adds inputs to the forms within the HTML. I don't want to inject the html into the webpage as I just need the form values to make some computations, but I am iterating over several ajax request and only a couple have this dynamic content. I would like a generic approach to where if the html contains js that adds inputs to the forms they get added (as in, I don't want to specifically single out certain ajax request and search for the values I need within the string). A simple example that I think illustrates the problem:

var x = `
<div id="hello">Hello </div>
<script>
    $('#test').append('World!');
</script>
`;
var data = $.parseHTML(x);
var y = $('#hello',data).text(); //want y to equal "Hello World!"
willjohnathan
  • 300
  • 3
  • 9
  • Possible duplicate of [Execute JavaScript code stored as a string](http://stackoverflow.com/questions/939326/execute-javascript-code-stored-as-a-string) – FireSarge Apr 11 '17 at 17:49
  • I saw that but wasn't sure how to get the script to modify the html string contained within x, not the document. – willjohnathan Apr 12 '17 at 02:43

0 Answers0