You are trying to access a variable inside a string. This makes no sense.
Did you really mean:
$("img:eq(" + indexImg + ")").show();
But a more efficient implementation:
$(this).prev().show();
The most effective implementation without side effects:
$("#rightShift").click(function(){ var $images = $("img"); // <-- Reference to all images $images.hide(); //var count = $images.length; //<-- Unused variable, delete it? $images.each(function(i) { $(this).prev().show(); }); }); $("#leftShift").click(function() { var $images = $("img"); $images.hide(); $images.last().prependTo("img"); // OR: $images.before($images.last()); $images.show(); });
Rob w source share