开发者

What can be used as [context] in jQuery( expression, [context] )?

The following code does not return anything:

$('.foo', $('<di开发者_如何学Pythonv 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.


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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜