Reputation: 716
var html = '<html><body><header>Header content</header><div id="container">Content I want</div><footer>Footer content</footer></body></html>'
Both $(html).find('#container')
and $(html).find('div')
seem to return []
.
I have tried using .find()
and .filter()
to do this, but to no avail.
Upvotes: 4
Views: 2706
Reputation: 78630
This is because when the html is parsed jquery is stripping the html
and body
tags. If you inspect the result, you will see a jquery object with 3 elements, header
, div
and footer
. As a result, you can do this:
$(html).filter('#container')
Upvotes: 3