如何在jQuery中选择这个容器元素 [英] How to select this container element in jQuery

查看:64
本文介绍了如何在jQuery中选择这个容器元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法选择当前点击的容器元素。

I having trouble to select the currently clicked container element.

我的Html

<div class="cparent">
foo1
<a href="javascript:void(0);" class="delete">Delete</a>
</div>

<div class="cparent">
foo2
<a href="javascript:void(0);" class="delete">Delete</a>
</div>

我的意思是当我点击删除链接时,相应的容器应该消失。我怎么能这样做?

I mean when I click on delete link, corresponding container should disappear. How can I do this?

我尝试了什么!

$(".cparent",this).html('Deleting...').delay(1000).fadeOut();// not working

我的脚本

$(".delete").live("click",function(){
 var cur = $(".delete").index(this);
 $(".cparent").eq(cur).html('Deleting...').delay(1000).fadeOut();
 });

以上一个也无效。请查看此示例以获得澄清。

Above one is also not working. Have a look at this Example for clarification.

推荐答案

使用 [ API Ref ] 方法:

$(this).parent().html('Deleting...').delay(1000).fadeOut();

作为第二个参数传递给jQuery函数找不到这个以上的元素。或者,您可以使用最近的 [ API参考] 方法:

Passing this as the second parameter to the jQuery function won't find elements that are above this. Alternatively, you can use the closest[API Ref] method:

$(this).closest('.cparent').html('Deleting...').delay(1000).fadeOut();

这篇关于如何在jQuery中选择这个容器元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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