jquery现场直播活动增加了dom元素 [英] jquery live event for added dom elements

查看:164
本文介绍了jquery现场直播活动增加了dom元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为现在或将来具有指定类并满足某些条件的任何DOM元素添加一个类。

I want to add a class to any DOM element that is on the page now or in the future that has a specified class and meets some criteria

所以对于某些伪代码

$('.location').live('load',function(){
    if($(this).find('input:first').val().substr(0,1) == "!"){ $(this).addClass('hidden')}
});

当然这不执行任何

编辑注意

这不起作用

$('.location').live('load',function(){
    alert('adding location');
});


推荐答案

jQuery的live()功能只是livequery的一部分插件,这是更丰富。如果您使用livequery,您可以执行某些操作。

jQuery's live() feature is just subset of the livequery plugin, which is much richer. If you use livequery you could do something like..

$('.location').livequery(function() {
   // perform selector on $(this) to apply class   
});

这将覆盖现有元素以及添加到DOM中的任何未来元素。

That will cover existing elements plus any future elements added to the DOM.

这篇关于jquery现场直播活动增加了dom元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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