views:

30

answers:

1

The following code does not return anything:

$('.foo', $('<div class="foo">foo</div><div class="bar">bar</div>').get(0)).html()

Is there any way to specify a string representation of xml/html as the context parameter of the jQuery function? I'm trying to select a section of an html document retrieved from an ajax request; the ajax callback (using $.get(), for example) provides the returned data -- in this case html.

+1  A: 

The problem in your example is that your context is two sibling elements. Using a wrapper element will allow you to select things inside it. Notice the difference here:

$('.bar', $('<div class="foo"><div class="bar">bar</div></div>')).html(); // outputs "bar"
Jimmy Cuadra
Excellent! That did it, thanks.
Phillip