This is driving me crazy... I made an array out of a "getElementsByTagName". Now, by using an onclick where the "this" method returns one of the values of that array, I cannot use "indexOf" to find its index. The console just tells me "arrayThumbs.indexOf is not a function".
This is the code:
var arrayThumbs = listThumbs.getElementsByTagName("img"); //Makes the array with the img tags
for(i=0;i<maxFiles-1;i++){
arrayThumbs[i].onclick = function(){
imgSelect = this; //Returns a valid value of the array, so far so good
indexThumb = arrayThumbs.indexOf(imgSelect); //Returns an ERROR...
};
}
The really weird part is that using the same syntax in other arrays this worked perfectly...
Thanks!
arrayThumbsactually at the point of the error? Use your browser's debugger to inspect it.indexOfneed a string value, and thatimgSelectmayb don't return a string... w3schools.com/jsref/jsref_indexof.aspindexOfcan take anything, not just strings..indexOf()definitions – one for Strings, one for Arrays. The latter is more-so applicable here and can accept any value. It's ability to match depends on===, which requires the types to be the same between the argument and the values within the array.