Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In jQuery, trying to get next-item-not-having-a-specific-class

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.

like image 444
user939737 Avatar asked Apr 20 '12 04:04

user939737


People also ask

What is next() in jQuery?

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()

How do you check if an element does not have a class in jQuery?

Use the classList. contains() method to check if an element does not have a specific class, e.g. if (! el. classList.

How to check child element in jQuery?

In jQuery, you can use $('#id'). children(). length > 0 to test if an element has children.


1 Answers

The below statement should solve your problem. $("#CONTAINER").find("div.focus").nextAll("div").not(".hidden").first();

like image 146
Vivek Viswanathan Avatar answered Nov 14 '22 01:11

Vivek Viswanathan