JQuery在当前项上添加类 [英] JQuery add class on current item

查看:83
本文介绍了JQuery在当前项上添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种方法可以在点击时更改更大的图像源。

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});
    });
});

谢谢: - )

推荐答案

这应该有效:

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

这篇关于JQuery在当前项上添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆