I have an html which looks like below
<div class="img-row">
<div class="img-column move">
<img class="demo" src="/image/001.jpg">
</div>
<div class="img-column move">
<img class="demo" src="/image/002.jpg">
</div>
<div class="img-column move moving">
<img class="demo" src="/image/003.jpg">
</div>
<div class="img-column move">.
<img class="demo" src="/image/004.jpg">
</div>
</div>
As you can see I have four child divs under the parent div .img-row
which contains the class .move
and the third child div contains an additional class .moving
. I want to select all the child before the child containing .moving
class. Note any child could contain the .moving
class and in any scenarios I want all the children before it.
So this is what I do
document.querySelectorAll('.move:not(.moving)')
But it also selects the last child in this case. How do I ensure only the children before the class .moving
is selected using javascript?
I found a similar question in stackoverflow Select all elements before element with class? but the solution provided is in css. I want a javascript solution instead.