The html code
<div id="slider">
<?php
while($gal = mysql_fetch_assoc($gallerydb))
{?>
<img data-store="<? echo $gal["ImageID"] ?>" src="SiteAdministration/ControlCenter/Gal/<? echo $gal["ImgPfad"] ?>"><?
}?>
</div>
The jQuery code
$(document).ready(function() {
$('#slider img[data-store='" + 2 + "']').fadeIn(300);
});
The html code shows a div with a while construct, that gets all images from a specific folder and adds an ID out of a database(numbers).
The jQuery code shows my attempt to select a img with a specific data-attribute value.
The problem is, that the img won't fade in, I suggest I messed up the selector.
Another question would be, how can I make it work, so that the selector starts with the lowest ID numer and ends with the highest, because the ID's can change.
Thanks in advance.
EDIT:
To solve my changing ID problem I just created another variable which increases automatically. If someone wants to know a solution.
<div id="slider">
<?php
$id = 1;
while($gal = mysql_fetch_assoc($gallerydb))
{?>
<img data-store="<? echo $id++ ?>" src="SiteAdministration/ControlCenter/Gal/<? echo $gal["ImgPfad"] ?>"><?
}?>
</div>
sliderStart = 1;
sliderNext = 2;
$(document).ready(function() {
$('#slider img[data-store="' + 1 + '"]').fadeIn(300);
startSlider();
});
function startSlider(){
count = $('#slider img').size();
loop = setInterval(function(){
if(sliderNext > count) {
sliderNext = 1;
sliderStart = 1;
}
$('#slider img').fadeOut(300);
$('#slider img[data-store="' + sliderNext + '"]').fadeIn(300);
sliderStart = sliderNext;
sliderNext = sliderNext + 1;
}, 3000)
}