Today I found a strange jquery selector 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 div
s 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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With