开发者

What would $('div, span', $('.test')).selector output? jQuery bug?

I have something similar to the following selector:

$('div, span', $('.test')).selector

I expect the selector that is produced to be:

.test div, .test span

开发者_如何转开发But its actually produces

.test div, span

What gives? I need the result to as expected otherwise its a huge headache.


Is it a bug? Well...it's debatable. It's not reliable in these situations (and many others), but per the jQuery API, it doesn't have to be.

.selector though accessible, isn't a supported or docunmented part of the API, so it may do some strange and unsupported things.

The short version: it won't so what you're after here, because it's designed for much simpler situations (usually one level deep), like .live() use internally.


Edit: If anyone's curious as to the why part of this, it's just how it's written, what you have: $('div, span', $('.test')) is actually doing a $('.test').find('div, span') which calls .pushStack() underneath, which is very simple: only appending a space and the new selector.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜