To find the next specific class using jQuery and then check if it has another class, you can use the .next() and .hasClass() methods. Here's how you can do it:

Assuming you have the following HTML structure:

html
<div class="parent"> <div class="first-class">First Div</div> <div class="second-class another-class">Second Div</div> <div class="third-class">Third Div</div> </div>

And you want to find the next element with class "second-class" and check if it has the class "another-class", you can use this jQuery code:

html
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { // Find the next element with class "second-class" var nextElement = $(".first-class").next(".second-class"); // Check if the next element has class "another-class" if (nextElement.hasClass("another-class")) { console.log("The next element has class 'another-class'."); } else { console.log("The next element does not have class 'another-class'."); } }); </script>

In this example, we use the .next(".second-class") to find the immediate sibling element with the class "second-class" after the element with class "first-class". Then, we use .hasClass("another-class") to check if this next element has the class "another-class".

Remember to include jQuery in your HTML file before using the script. In the example above, I included jQuery using the script tag from a content delivery network (CDN). You can also download jQuery and include it from your local file if you prefer.

Have questions or queries?
Get in Touch