0

I'm trying to get the content of a file, and then append something to the body tag like this:

$.get('myfile.php', function(html){
    html.find('body').append("<h1>TESTING</h1>");
});

But the above code doesn't work!

I even triend with parseHTML like this:

$.get('myfile.php', function(html){
    var parsedHtml = $.parseHTML(html);
    parsedHtml.find('body').append("<h1>TESTING</h1>");
});

But that didn't work either.

Any idea please?

user765368
  • 19,590
  • 27
  • 96
  • 167
  • Possible duplicate of [Parsing returned HTML from jQuery AJAX request](https://stackoverflow.com/questions/20007721/parsing-returned-html-from-jquery-ajax-request) – bigless Jun 11 '18 at 22:03
  • By "does not work" do you mean you do not see the results on the page? Because in both of your cases, logical errors aside, you are not appending the html to the page any where as a result. – Taplar Jun 11 '18 at 22:04
  • Have you tried making the html a jQuery object? `$.get('myfile.php', function(html){ $(html).find('body').append("

    TESTING

    "); });`
    – PoorlyWrittenCode Jun 11 '18 at 22:10
  • How do you know? You aren't doing anything with the result. First one definitely won;t work since the `html` is just a string – charlietfl Jun 11 '18 at 22:14
  • For the second try, did you try this; `$(parsedHtml).find('body').append("

    TESTING

    "); `
    – Vinit Divekar Jun 12 '18 at 03:01

0 Answers0