等到HTML元素得到一个类,然后做点什么 [英] Wait until HTML elements gets a class then do something

查看:64
本文介绍了等到HTML元素得到一个类,然后做点什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在等待document.ready事件,以便在页面上执行某些操作.

I am waiting for the document.ready event in order to do something on my page.

遗憾的是,我无法更改的其他脚本在调用我的脚本后仍无法发挥其魔力.因此,无法在类名称上进行jquery选择,因为该类在DOM中尚不存在.

Alas some other script, which I cannot change, has not worked its magic yet once my script is called. Hence, jquery selection on the class name fails as the class does not yet exist in the DOM.

这就是为什么我要告诉我的函数侦听直到某个元素获得某个类,然后对其进行处理.

This is why I want tell my function to listen until an element gets a certain class, then do something with it.

我该如何实现?

推荐答案

添加课程后,您可以触发一些事件.

You could trigger some event once you added the class.

示例:

$('#ele').addClass('theClass');
$(document).trigger('classGiven')


$(document).bind('classGiven',function(){
    //do what you need
});

这篇关于等到HTML元素得到一个类,然后做点什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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