javascript - Find index in array different from the array that loaded -
line 35, before alert, returns -1. tried $(this).index()
same result. here should do: clicking en.gif
should return 4, grand_array_pics[4]
should give me en_array_pics
, load .gifs
in array.
$(document).ready(function () { var main_pics = ["an.gif", "bn.gif", "cn.gif", "dn.gif", "en.gif", "gn.gif"]; var starting_pics = ["an.gif", "cn.gif", "en.gif"]; var an_array_pics = ["bn.gif", "en.gif", "gn.gif", "an.gif","dn.gif"]; var bn_array_pics = ["cn.gif", "dn.gif", "gn.gif"]; var cn_array_pics = ["dn.gif", "gn.gif", "an.gif", "cn.gif"]; var dn_array_pics = ["en.gif", "an.gif", "cn.gif"]; var en_array_pics = ["gn.gif", "an.gif", "cn.gif", "en.gif"]; var gn_array_pics = ["an.gif", "cn.gif", "en.gif", "gn.gif"]; var grand_array_pics = [ an_array_pics, bn_array_pics, cn_array_pics, dn_array_pics, en_array_pics, gn_array_pics ]; var = 0; (i = 0; < starting_pics.length; i++) { $("<img/>").attr("src", "images/" + starting_pics[i]).load(function () { $(this).appendto("#main"); $(this).addclass("pics"); }); } $("#main").on("click", ".pics", function () { var j = $.inarray(this, main_pics); alert(j); $("#sidebar .pics").remove(); $(this).clone().appendto("#train"); $(this).clone().appendto("#sidebar"); $("#main .pics").remove(); var chosen_pics_array = grand_array_pics[j]; var count = chosen_pics_array.length; var k = 0; (k = 0; k < count; k++) { $("<img/>").attr("src", "images/" + chosen_pics_array[k]).load(function () { $(this).appendto("#main"); $(this).addclass("pics"); }); } }); }); //end ready
this
dom <img>
element, while main_pics
array of strings. never found inside there. use
var j = $.inarray(this.src.split("/").pop(), main_pics);
Comments
Post a Comment