It's a while ago, but maybe you're still interested in it..
The intern implementation of $(String)
is not able to build an jQuery object that contains head
or body
tags. It will simply ignore them and move all elements inside on level up.
So if your string is for example
<html>
<head>
<meta ...>
</head>
<body>
<div id="a"/>
</body>
</html>
the resulting jQuery object will be an array of two elements
[<meta ...>, <div id="a" />]
to get a body
-like jQuery object cut everything but the body content before passing it to jQuery:
body = '<div id="body-mock">' + html.replace(/^[sS]*<body.*?>|</body>[sS]*$/ig, '') + '</div>';
var $body = $(body);
now things work as expected.. for example
$body.find('#a')
Hope that helps..
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…