在jquery中监听类的更改 [英] Listen for change of class in jquery
问题描述
在jquery中是否有一种方法可以监听节点类的更改,然后在类更改为特定类时对其执行某些操作?具体来说,我正在使用带有幻灯片的jquery工具选项卡插件,并且在播放幻灯片时,我需要能够检测焦点何时在特定的选项卡/锚点上,以便我可以取消隐藏特定的div。
Is there a way in jquery to listen for a change to a node's class and then take some action on it if the class changes to a specific class? Specifically, I'm using the jquery tools tabs plugin with the slideshow and as the slideshow is playing, I need to be able to detect when the focus is on a particular tab/anchor so that I can unhide a specific div.
在我的具体示例中,我需要知道何时:
In my specific example, I need to know when:
<li><a class="nav-video" id="nav-video-video7" href="#video7-video">Video Link 7</a></li>
在添加current类时更改为以下内容:
changes to the following with the class "current" added:
<li><a class="nav-video" id="nav-video-video7 current" href="#video7-video">Video Link 7</a></li>
然后我想在那一刻取消隐藏div。
Then I want to unhide a div at that moment.
谢谢!
推荐答案
以下是一些可能提供解决方案的其他发现:
Here are some other finds that might provide a solution:
- Most efficient method of detecting/monitoring DOM changes?
- How can I detect when an HTML element’s class changes?
- Monitoring DOM Changes in JQuery
以及在#2中建议,为什么不使当前
添加一个类而不是ID,并让以下CSS处理显示/隐藏操作。
And as it was suggested in #2, why not make current
a class that is added, rather than a ID, and have the following CSS handle the show/hide action.
<style type='text/css>
.current{display:inline;}
.notCurrent{display:none;}
</style>
可能值得研究。on()in jquery 。
这篇关于在jquery中监听类的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!