'How to get div sequence number from collections of div

I want to get sequence index number of div from collection of div. Many div are same. I have div like follows:

 <div class='main-Div'>


<div class='drag-box'>
     <div class='get-box'>
        <div class='subject-box'>
            <a href='#' class='open-Window'>Add Details
            </a>
        </div>
    </div>
</div>

    <div class='drag-box'>
     <div class='get-box'>
        <div class='subject-box'>
            <a href='#' class='open-Window'>Add Details
            </a>
        </div>
    </div>
</div>

If I click on 'Add Details' link then it return 1 or 2 number of its(drag-box div) own index(1st or 2nd).



Solution 1:[1]

You can use index(). Try this:

$('.open-Window').click(function() {
    var index = $(this).closest('.drag-box').index();
    console.log(index);
});

Example fiddle

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rory McCrossan