We have answer of your question!

100% solved queries, no empty question

Question: jquery selector of class who have specific node immediatey after


0

consider the following html:

    <div class="a"> pick me 1</div>
    <div class="b"> stuff </div>
    <div class="a"> stuff </div>
    <div class="a"> stuff </div>
    <div class="a"> pick me 2</div>
    <div class="b"> stuff </div>
    <div class="a"> stuff </div>
    <div class="c"> stuff </div>
    <div class="b"> stuff </div>

I'd like to select only the divs which have .a and have .b immediately after, so I'll only get the pick me divs

Question author Nick-ginanto | Source

Answer


1


You need to start with the .b elements and step back to their preceding .a elements:

$('.b').prev('.a');

jsFiddle demo

Note that this does not include the .b elements, only the .a elements. A selector like .a + .b, on the other hand, would match the same structure but give you .b elements instead.

Answer author Boltclock

Tickanswer.com is providing the only single recommended solution of the question jquery selector of class who have specific node immediatey after under the categories i.e jquery , jquery-selectors , . Our team of experts filter the best solution for you.

Related Search Queries:


You may also add your answer

Thanks for contributing an answer to Tick Answer!