I need to get the class attribute from the body element of a page object retrieved with $.get(). In my example below, fullContent is set to the object but I can’t select the body element… I’d rather not resort to text manipulation to get this
$.get(url, refreshFullContent);
var refreshFullContent = function(response, status, xhr)
{
fullContent = response;
var bodyclass = $(fullContent).find("body").attr("class");
$("body").attr("class", bodyclass);
}
Is there a way to get this with selectors on the object (like I’m trying to do in this example)? If not, what is the best way to get this from the text? xhr.responseText contains the string of the entire response.
If you’re getting a full HTML document response, you won’t get consistent behavior between browsers.
Some browsers will strip away the
headandbodyelements.You could try this, but no guarantees: