1. Question demo: Why is the index value of a footer so big that index is not looking for sibling level elements? It also limits the range of a under footer.
Workaround : alert( $("#footer a").index($(this)) );
parsing : The demo is the node that gets itself. .index()
further comprehensive explanation of the problem:
- If you do not pass a parameter to a
.index()
method, the return value is the position of the first element in the collection of jquery objects relative to its sibling element.
- If the argument is a set of DOM elements or jquery objects, the return value is the position of the passed element relative to the original collection.
- If the parameter is a selector, the return value is the position of the original element in relation to the selector match element. If no matching element is found, the return parameter is the JQ object, or the DOM object.
The following code is equivalent:
$(this).index(‘a‘) != $(this).index();
$(this).index(‘a‘) == $(this).index($("a"));
2015.4.19 Why footer The index value of a is so big