I have a big HTML-string containing multiple child-nodes.
Is it possible to construct a jQuery DOM object using this string?
I’ve tried $(string) but it only returns an array containing all the individual nodes.
Imtrying to get an element which i can use the .find() function on.
Update:
From jQuery 1.8, we can use $.parseHTML, which will parse the HTML string to an array of DOM nodes. eg:
DEMO
DEMO
What’s happening in this code:
$('<div/>')is a fake<div>that does not exist in the DOM$('<div/>').html(string)appendsstringwithin that fake<div>as children.contents()retrieves the children of that fake<div>as a jQuery objectIf you want to make
.find()work then try this:DEMO