HTML:
Div 1
Div 2
Div 3
<
index() gives index of element with respect to its siblings. The first div with class text is 5th element and has index 4, br is at 5 index and next div with class test has index 6 and so on. We can check the indexes of each element by the following demo
Live Demo
$("#parent1 *").each(function () {
alert("TagName >> " + this.tagName + ", Index >> " + $(this).index() + ", Text " + $(this).text());
});
If no argument is passed to the .index() method, the return value is an integer indicating the position of the first element within the jQuery object relative to its sibling elements, Reference.