How to get a HTML element from a string with jQuery

I'm looking for a way to get a HTML element from a string that contains HTML. Is it possible to use a jQuery selector to do this?

I have a Javascript function that gets an entire page from the server, but I only need one element from that page.


Solution 1:

Yes, you can turn the string into elements, and select elements from it. Example:

var elements = $(theHtmlString);
var found = $('.FindMe', elements);

Solution 2:

Just wrap the html text in the $ function. Like

$("<div>I want this element</div>")