0

I have the following situation below fiddle:

http://jsfiddle.net/ze6wv2e2/

When I click on a "view_larger" class, I am trying to get the index of the ".inner" parent class in reference to the whole page.

For example, if I click on the 2nd view_larger class, The index of ".inner" class should be equal to 1.

This is what I have so far:

$(".view_larger").click(function(){
    var classIndex = $(this).parent().index();
    console.log("classIndex");
})

I hope this is clear enough.

Thanks.

0

1 Answer 1

1

You need to use below if you want the index to be based on all the .inner elements. Then use the .index(selector) version, this will give the index of the element based on the element set of the passed selector.

var classIndex = $(this).parent().index('.inner');

Clicking hi3 will give you 3 in this case

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I knew it was something simple I was missing!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.