javascript - JQuery add class on current item - Stack Overflow

I have this method that changes an larger image source on click. I need to add a 'current' cl

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

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

Share Improve this question asked May 25, 2009 at 11:41 janhartmannjanhartmann 15k17 gold badges87 silver badges140 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

This should work:

$("ul.timgs li a").click(function(e) {
  $(".current").removeClass("current");
  $(this).addClass("current");
  ...
}

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743713790a4494637.html

相关推荐

  • javascript - JQuery add class on current item - Stack Overflow

    I have this method that changes an larger image source on click. I need to add a 'current' cl

    6天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信