开发者

jQuery string to DOM without DOM insertion

I have a textarea with the following content (innerHTML):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>

</body>
</html>

To prepare the content for DOM parsing with jQuery I do the following (temp is just a div):

$('#temp').append(input.val());

console.log($('#temp').html());

As pointed out at jQuery object from complete HTML document, the head, body, html and doctype tags are gone:

<meta charset="utf-8">
<title></title> 

So is t开发者_如何学Gohere any other way not to append to the DOM and still get DOM elements to work with? Iframe may be a last resort but that would be ugly.


You could do this..

 $(input.val()).find('your-selector')

Or, you could pass it as context..

$('your-selector', $(input.val()))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜