jquery更改类名 [英] jquery change class name

查看:129
本文介绍了jquery更改类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改td标签的id:

I want to change the class of a td tag given the td tag's id:

<td id="td_id" class="change_me"> ...

我想能够在一些其他dom对象的单击事件。

I want to be able to do this while inside the click event of some other dom object. How do I grab the td's id and change its class?

推荐答案

您可以设置不管是什么),请使用 .attr() ,例如:

You can set the class (regardless of what it was) by using .attr(), like this:

$("#td_id").attr('class', 'newClass');

如果要添加类,请使用 .addclass() ,如下所示:

If you want to add a class, use .addclass() instead, like this:

$("#td_id").addClass('newClass');

或者使用 .toggleClass()

$("#td_id").toggleClass('change_me newClass');

以下是专门为属性指定的jQuery方法的完整列表。

Here's the full list of jQuery methods specifically for the class attribute.

这篇关于jquery更改类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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