开发者

Jquery selector problem about "+"

Today I found a strange jquery sel开发者_如何学Cector in the following code:

$(this).find("+div.parent").hide();

I've searched this in Jquery API and only found what pre_element+next_element means.What does the + do in the code?

Thanks.


the selector + matches the element that follows the previous one

for example if you want to matches all the divs that are after bold text you can use this selector:

$("b+div")

so if $(this) is reference to <b>:

$(this).find('+div.parent')

will match all the div with class parent that are immediately after <b>


the + is an Adjacent Sibling selector

it will select the immediate sibling of the this, it is equivalent to next()

$(this).find("+div.parent").hide();

is the same as

$(this).next("div.parent").hide();


It'll find the div with the class parent adjacent to whatever $(this) is.

Fiddle here: http://jsfiddle.net/prbRA/1/


Find all the div with class parent which are immediately after the selected element $(this)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜