在jquery中监听类的更改 [英] Listen for change of class in jquery

查看:586
本文介绍了在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:


  1. Most检测/监控DOM变化的有效方法?

  2. 如何检测HTML元素的类何时发生变化?

  3. 监控JQuery中的DOM更改

  1. Most efficient method of detecting/monitoring DOM changes?
  2. How can I detect when an HTML element’s class changes?
  3. 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屋!

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