jquery - Javascript function to select images only works on first image -
here function i'm using select photos. become selected being added array , having green check mark placed on them. when clicked again, should removed array, , check mark should removed well.
this works fine, except if select, unselect photo, not let select again after that. exception first photo in list (top left) , i'm not sure why is. can select , unselect many times , works fine. photos behave this.
here code:
var selectedphotos = new array(); function selectvehicle(photoid) { if ( selectedphotos.indexof(photoid) > -1 ) { $('#check'+photoid).css('z-index', '-1'); selectedphotos.splice(photoid, 1); } else { selectedphotos.push(photoid); $('#check'+photoid).css('z-index', '1'); } }
you can view page in action here: http://lindseymotors.com/unassignedphotos.php
you need pass index of element remove in splice index @ start changing array
var index = selectedphotos.indexof(photoid); if(index > -1){ selectedphotos.splice(index , 1); }
complete code
var selectedphotos = new array(); function selectvehicle(photoid) { var index = selectedphotos.indexof(photoid); if(index > -1){ selectedphotos.splice(index, 1); $('#check'+photoid).css('z-index', '-1'); } else { selectedphotos.push(photoid); $('#check'+photoid).css('z-index', '1'); } }
Comments
Post a Comment