Hello, there are several elements with the class .class! After some of them, there is ul c id = "tree". How to choose those elements .class, after which immediately comes a similar ul? If ul goes, for example, through a line, then this element cannot be taken.

So you can generally choose?

    2 answers 2

    Item ID must be unique. Using multiple ul with id = "tree" is wrong.
    Use class better.

    Given this remark, the decision will be:

    $('ul.tree').prev().filter('.class'); 

    Select the elements immediately before ul.tree. Leave in the selection only elements with the class .class

    Example link

       .tree + .class 

      http://jquery-docs.ru/selectors/

      • @Fuad Cavadov, you need to select .class, which are not AFTER .tree, but BEFORE it. Such a solution will not work. - VenZell