Use the jquery prev () method to find the first element of the same level, jqueryprev
Retrieve each section and find the first compatriot element of the class "selected:
$ ("P"). prev (". selected ")
The. prev () method allows us to search for the first compatriot element of these elements in the DOM tree and construct a new jQuery object with matching elements.
The. prev () method finds the first element at the same level of the current element.
Jquery prev () method
$ ("P") is an array
Therefore, the returned result is an array.
The first one does not
The second one has
So it is [<div> <span> Hello Again </span> </div>]
[] Is an array
Jquery selector problem: how to obtain the first element containing a div following the element of the same level
<Input/> <span> <a> </a> <span> <div> </div>
$ ("Input"). nextAll ('div '). eq (0 );
Do not use css selectors.