For debugging purposes, I need to output the IDs of all previous images in a check. The issue arises when trying to assign classes to all previous elements using the script below, as the images are not being added to the correct classes.
$(document).on('click', 'img', function() {
var t=$(this);
t.prevAll().removeClass('t2').addClass('t1');
t.nextAll().removeClass('t1').addClass('t2');
To see an example, visit this jsFiddle. When clicking on any image, my goal is to assign the previous images to one class and the next image to another class.