移除元素之前的事件 [英] Event to remove element before

查看:78
本文介绍了移除元素之前的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何在jQuery中编写一个事件,以便如果单击任何链接,它将不删除周围的分隔线,而是删除其前面的分隔线?

How would I write an event in jQuery so that if I click any of the links it'll delete not the divouter surrounding it, but the divouter before it?

    <div class='divouter'>
<a href='#'>Link</a>
    </div>
    <div class='divouter'>
<a href='#'>Link</a>
    </div>
    <div class='divouter'>
<a href='#'>Link</a>
    </div>
    <div class='divouter'>
<a href='#'>Link</a>
    </div>

推荐答案

尝试一下:

$(".divouter a").click(function() {
    $(this).parent(".divouter").prev(".divouter:last").remove();
});

这篇关于移除元素之前的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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