问题描述
我正在使用jQuery来显示和隐藏面板.上面有一个小箭头图像,在隐藏和显示时也会发生变化.我的代码是
I am using jQuery for a panel to show and hide. There is a small arrow image on it which also changes on hide and show. My code is
<div class="trigger-m"><span id="toppanelarrow"> </span></div>
现在,在面板打开时将一个类添加到_up,在面板关闭时将一个类添加到_down.我有相应的上下箭头图像.
Now a class is added to_up when the panel opens and to_down when the panel closed. I have respective up and down arrow image for this.
有人可以帮我在'toppanelarrow'的点击事件中添加jQuery,以便将新类添加到跨度中.
Can someone help me adding a jQuery on click event of 'toppanelarrow' so a new class gets added to the span.
我尝试了$().addClass().removeClass()
,但是没有用.
I have tried $().addClass().removeClass()
but this didn't work.
更新:请找到小提琴实现 http://jsfiddle.net/B5QUj/4/
Update: Please find the fiddle implementation http://jsfiddle.net/B5QUj/4/
谢谢
推荐答案
如果元素上有一个以以下内容开头的类:
If you have one class on the element to start with:
$('#foo').on('click', function () {
$(this).toggleClass('to_up to_down');
});
是您所需要的.
演示: http://jsfiddle.net/kXNk8/
这篇关于jQuery:单击事件时更改类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!