Why is one of these jQuery selectors working and the other not?

$.prev("div.a").find('.b').

$.prev("div.a .b").

One works, but the other does not. Who cares?

+3
source share
2 answers

Well, the selector works, it just doesn't give you what you want:

According to jQuery Docs .prev([expr]) :

Get a set of elements containing unique previous siblings of each of the agreed set of elements. Use an optional expression to filter a consistent set. Only immediately the previous sibling returns, not all previous brothers and sisters.

: $(elem).prev("div.a").find('.b') DOM, div.a - .find() .b

: $(elem).prev("div.a .b") , div.a .b .

.

+5

find() , ... , .b div.a, .

:

<div class="a">
  <div class="b">

:

<div class="a b">

: http://docs.jquery.com/Traversing/find

0

Source: https://habr.com/ru/post/1719339/


All Articles