First:
.closest('.notice')
It will take .notice itself or it will take whats nearest the .notice up the dom tree?
.next('.notice') – it will grab whats down the dom tree, right?
Another one:
$('#celebTree ul').hide().before('<div class="bla"></div>').prev().addClass('handle closed')
with the .prev jQuery should select an element before “bla” and apply the class. But it is applying the class to the element that I am inserting with .before method. Why it is like this?
.closest('notice')is the closest parent that matches or the element itself if it matches:.next('notice')selects the next element sibling if it matches:.before()doesn’t return a new jQuery object, it returns the old one that you inserted content before to:Since you just inserted before the element and
prevoperates on'#celebTree ul'here,prevwill take the previous element sibling, which is that content.