Oleksandr IY
Oleksandr IY

Reputation: 3106

get body html of jquery object

I convert returned page content to jquery object. How can I get html content of the body tag? $(data).find('body').html() seems incorrect in this case. Here is my full script code

            $.get($(this).attr('href'), function (data) {
                var $dataj = $(data);
                $dataj.find('#header').remove();
                $('#content_left').append($dataj.find('body').html());
            });

So actually I need convert jquery object back to html string

Upvotes: 0

Views: 96

Answers (1)

mondersky
mondersky

Reputation: 471

basic javascript is always the turnaround to this kind of situations :

  $.get($(this).attr('href'), function (data) {
    var jsElement = document.createElement('html');
    jsElement.innerHTML = data;
    var $dataj = $(jsElement);
    $dataj.find('#header').remove();
    $('#content_left').append($dataj.find('body').html());
});

Upvotes: 1

Related Questions