1

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 :-)

2 Answers 2

9

This should work:

$("ul.timgs li a").click(function(e) {
  $(".current").removeClass("current");
  $(this).addClass("current");
  ...
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.