I'm trying to get at the first not(.hidden) div after the .focus div. In this example the focus is X2, and I should get back X5, skipping X3 and X4 because they are hidden.
<div id='CONTAINER'>
<div id='X1'>eks1</div>
<div id='X2' class='focus'>eks2</div>
<div id='X3' class='hidden'>eks3</div>
<div id='X4' class='hidden'>eks4</div>
<div id='X5'>eks5</div>
<div id='X6'>eks6</div>
</div>
This seems like it should be a pretty simple jquery question, but I'm fairly new to this stuff.
The next() is an inbuilt function in jQuery which is used to return the next sibling of the selected element. Siblings are those having same parent element in DOM Tree. Document Object Model (DOM) is a World Wide Web Consortium standard. This defines for accessing elements in the DOM tree. Syntax: $(selector).next()
Use the classList. contains() method to check if an element does not have a specific class, e.g. if (! el. classList.
In jQuery, you can use $('#id'). children(). length > 0 to test if an element has children.
The below statement should solve your problem.
$("#CONTAINER").find("div.focus").nextAll("div").not(".hidden").first();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With