I am trying to return, using .index method, the position of the picture I am clicking on and then use that number in another variable that has to be external to the function.
var index;
$('.product img').click(function () {
index = $( ".product img" ).index( this ); //it returns an integer, as expected
})
var myProduct = 'product'+ (index + 1)+'.php'; // it returns productNaN.php
Only that, although the index method works properly, in my second variable I get instead of an integer NaN.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…