Use Jquery Selectors on $.AJAX loaded HTML?

Solution 1:

One note I will add which is from a similar problem on here is that if your AJAX returns the following:

<div class="test">Hello</div>
<div class="one">World</div>

The following jQuery Won't work:

$(data).find('div.test');

as the divs are top level elements and data isn't an element but a string, to make it work you need to use .filter

$(data).filter('div.test');

Solution 2:

// Finds all div elements within an XML document from an AJAX response.
$("div", xml.responseXML);