开发者

jQuery queries on variables fails in IE

T开发者_如何学运维he following code returns the html of the selected element contained in the data variable in all the major browsers, except IE.

$("#blapp", data).html();

Does anyone know why?

A workaround is to insert the data into the DOM, select the wanted data and then subsequently remove the temp stuff. I was though wondering if anyone knows a better solution?


I've got a gut feeling that data is an entire HTML document. If so, you'll get different results between browsers when trying to make a jQuery object out of it.

If that's the case, try this instead:

$('<div>' + data + '</div>').find( '#blapp' ).html();

Another option would be to try using .filter() instead of .find() (which you're doing now via the context argument). Although this may cause it to stop working in some browsers.

$(data).filter('#blapp').html();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜