views:

692

answers:

2

I have this method that changes an larger image source on click.

I need to add a 'current' class on the selected. I have no problem adding this class,but I need it to remove the class on the other, previous, selected item.

This is the code I'm using at the moment:

$(document).ready(function() {
    $("ul.timgs li a").click(function(e) {
        e.preventDefault();
        var path = $(this).attr("href");
        $("div.tour-image img").attr({"src": path});
    });
});

Thanks :-)

+4  A: 

This should work:

$("ul.timgs li a").click(function(e) {
  $(".current").removeClass("current");
  $(this).addClass("current");
  ...
}
peirix
Oh well. Of course. Thanks! :-)
meep
A: 

Before you add the "current" class to the new current item, remove it from the previous current item:

$(".current").removeClass("current");
Mario Menger