This is my code :
if ($('#fotosingola_6985') instanceof jQuery) {
console.log($('#fotosingola_6985').attr('id'));
console.log($('#fotosingola_6985').index(".classObj"));
}
well : the output of this code is :
fotosingola_6985
-1
How can it be possible? jQuery spec says If a selector string is passed as an argument, .index() returns an integer indicating the position of the original element relative to the elements matched by the selector. If the element is not found, .index() will return -1.
But the element (yes, it is a jQuery element, I made the control) is found : in fact it returns its id.
Surrounding HTML :
<div id="exp-gallery-dettaglio-slideshow-overflowed">
<a href="javascript:void(0);" class="classObj" id="fotosingola_6529"> </a>
<a href="javascript:void(0);" class="classObj" id="fotosingola_6985"> </a>
<a href="javascript:void(0);" class="classObj" id="fotosingola_6990"> </a>
<a href="javascript:void(0);" class="classObj" id="fotosingola_6998"> </a>
<a href="javascript:void(0);" class="classObj" id="fotosingola_6912"> </a>
</div>
The REAL strange behaviour :
If I do :
console.log($('.classObj').index('#fotosingola_6985'));
it return -1. But, if I do :
console.log($('.classObj').index($('#fotosingola_6985')));
it returns 1, which is correct. How can this be possible?
As your elements are siblings you can code:
indexaccepts a jQuery object or DOM element:http://jsfiddle.net/6sDpx/