jQuery Live遍历parent()选择器 [英] jQuery Live traversal parent() selector

查看:86
本文介绍了jQuery Live遍历parent()选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(".hovertip").parent().live('hover', function() {
  ...

上面的代码似乎没有注册.

这似乎也不起作用:

$(".hovertip").parent().live({
  mouseenter:
    function() {
    ...

使用jQuery选择器和.hover()或mouseenter:和mouseleave :?


更新:我创建了一个单独的问题来解决此问题引起的动态DOM问题:解决方案

尝试:

$(".hovertip").parent().on('hover', function() {
    alert('yay');
});

注意: .on是jQuery 1.8中引入的.

工作演示 http://jsfiddle.net/pRB8n/ 将鼠标悬停在测试上-在演示中

如果您真的想使用.delegate,请尝试以下操作: http://jsfiddle.net/TURBX/2/- http://api.jquery.com/delegate/

委托
将符合条件的处理程序附加到所有元素的一个或多个事件 选择器,现在或将来,基于一组特定的根 元素.

希望休息能满足需求:)

P.S. -不推荐使用.live:如果您喜欢的话,请继续-我的旧帖子在这里:) http://api.jquery.com/live/ 已弃用"

$(".hovertip").parent().live('hover', function() {
  ...

The above code doesn't seem to register.

This doesn't seem to work either:

$(".hovertip").parent().live({
  mouseenter:
    function() {
    ...

Any examples of .live, .delegate, .bind, or .on working with a jQuery selector and a .parent() selector with .hover() or mouseenter: and mouseleave:?


Update: I've created a separate question to address the dynamic DOM issue this Question has raised: jQuery .on() with a .parent() and dynamic selector

解决方案

Try:

$(".hovertip").parent().on('hover', function() {
    alert('yay');
});

Note: .on was introduced in jQuery 1.8.

Working demo http://jsfiddle.net/pRB8n/ Hover over test test - in the demo

If you really want to use .delegate try this please: http://jsfiddle.net/TURBX/2/ - http://api.jquery.com/delegate/

Delegate
Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.

Hope rest fits the needs :)

P.S. - .live is deprecated: for further if you keen - my old post here: :) What's wrong with the jQuery live method?

under category you will see: http://api.jquery.com/live/ "deprecated"

这篇关于jQuery Live遍历parent()选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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