jQuery: Find next Element with same class

Zwen2012

I want the next Element with the same class. So I have a click action on the class "calculationContainer". When I click this element, I want to have access of the next element with the class "calculationContainer". But all I tried doesn't work. Maybe someone can help me with this?

I have this HTML Code:

<div class="body">
    <div class="inner">
        <div class="calculationContainer">
            <div class="element">
                <input type="text" id="name1">
            </div>
        </div>
    </div>
</div>
<div class="body">
    <div class="inner">
        <div class="calculationContainer">
            <div class="element">
                <input type="text" id="name2">
            </div>
        </div>
    </div>
</div>
<div class="body">
    <div class="inner">
        <div class="calculationContainer">
            <div class="element">
                <input type="text" id="name3">
            </div>
        </div>
    </div>
</div>

And my jQuery:

$('.calculationContainer').on('click', function() {
        var amountCalculationContainer = $(this);
        var nextAmountCalculationContainer = amountCalculationContainer.next('.calculationContainer');  //<- Only finds the div with class "element"

});
Kartikeya Khosla

Try This :-

$('.calculationContainer').on('click', function() {
    var $elem = $(this).closest('div.body').next().find('div.calculationContainer')    
});

Use .closest() to traverse up and find first div.body parent and then use .next() to get next element and then find div.calculationContainer with .find().

Handle the situation when .calculationContainer is at last position(as shown in demo).

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get next element with same class in jquery on click

From Dev

jquery find next element with class name

From Dev

How to find the next element of parent siblings with same class

From Dev

Find next element in jquery

From Dev

JQuery check if the next visible element has the same class

From Dev

JQuery - How to find the next occurence of element with specific class

From Dev

jQuery, find next element with id

From Dev

jQuery if element is next and has class?

From Dev

jQuery if element is next and has class?

From Dev

jquery find next class in a list

From Dev

jQuery select a class and a 'next' element of this class

From Dev

How to select the next element with same class?

From Dev

scroll to next element with same parent class

From Dev

Find next select element inside class

From Dev

jquery click element with same class

From Dev

jquery next() and find() to remove class from element doesn't work for me

From Dev

jquery next() and find() to remove class from element doesn't work for me

From Dev

Find next element out of parent using jQuery

From Dev

jquery find next element without attribute

From Dev

Jquery - find next element in each loop

From Dev

Remove class from next element jQuery

From Dev

Smooth scrolling to next class element jquery

From Dev

jQuery apply css class to next single element

From Dev

jQuery check if input is same as element with same class

From Dev

another jquery find next class not sibling for slideToggle

From Dev

Find all next classes until class jquery

From Dev

Find next img element using known element id javascript/jquery

From Dev

jQuery: Filter classes and search for element with same class

From Dev

Get next element with same class, regardless of its location in the DOM

Related Related

  1. 1

    Get next element with same class in jquery on click

  2. 2

    jquery find next element with class name

  3. 3

    How to find the next element of parent siblings with same class

  4. 4

    Find next element in jquery

  5. 5

    JQuery check if the next visible element has the same class

  6. 6

    JQuery - How to find the next occurence of element with specific class

  7. 7

    jQuery, find next element with id

  8. 8

    jQuery if element is next and has class?

  9. 9

    jQuery if element is next and has class?

  10. 10

    jquery find next class in a list

  11. 11

    jQuery select a class and a 'next' element of this class

  12. 12

    How to select the next element with same class?

  13. 13

    scroll to next element with same parent class

  14. 14

    Find next select element inside class

  15. 15

    jquery click element with same class

  16. 16

    jquery next() and find() to remove class from element doesn't work for me

  17. 17

    jquery next() and find() to remove class from element doesn't work for me

  18. 18

    Find next element out of parent using jQuery

  19. 19

    jquery find next element without attribute

  20. 20

    Jquery - find next element in each loop

  21. 21

    Remove class from next element jQuery

  22. 22

    Smooth scrolling to next class element jquery

  23. 23

    jQuery apply css class to next single element

  24. 24

    jQuery check if input is same as element with same class

  25. 25

    another jquery find next class not sibling for slideToggle

  26. 26

    Find all next classes until class jquery

  27. 27

    Find next img element using known element id javascript/jquery

  28. 28

    jQuery: Filter classes and search for element with same class

  29. 29

    Get next element with same class, regardless of its location in the DOM

HotTag

Archive