画像をクリックして、htmlページに書き込まれた以前のすべての画像要素IDを取得したい画像スライダーがあります。以前の要素をすべて印刷しようとするとimg
、循環 div のためにすべてが印刷されます。たとえば、画像 #5 をクリックすると、1、2、3、4、および 5 のみが取得されます。以下のコードは、4、3、2、1、12、11、10、9 などを返します。 .
var ids = t.prevAll().removeClass('t2').addClass('t1').map(function(){
return this.id;
}).get().join();
console.log(ids);
$(document).ready(function () {
/* Reading the data from XML file*/
$.ajax({
type: "GET",
url: "photos.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('item').each(function(){
var path = $(this).attr('path');
var width = $(this).attr('width');
var height = $(this).attr('height');
var id = $(this).attr('id');
var alt = $(this).attr('alt');
var longdesc = $(this).find('longdesc').text();
var description = $(this).find('desc').text();
$('#myImageFlow').append('<img src="'+path+'" id='+id+' height="'+height+'" width="'+ width+'" longdesc="'+longdesc+'" alt="'+alt+'"/>');
imgArr[i] = description;
imgFront[i]=longdesc;
backimg[i]=longdesc;
frontimg[i]=path;
i = i+1;
});