定位类的单个实例 [英] Target single instance of a class

查看:62
本文介绍了定位类的单个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CSS隐藏当某人单击链接时要显示的内容.页面上有多个实例.

I'm using css to hide content that I want to reveal when a person clicks a link. There are multiple instances on the page.

我已经建立了一个示例,但是当前单击任何链接将显示所有内容.

I've set up an example but currently clicking any of the links reveals all of the content.

http://jsfiddle.net/paulyabsley/rHD43/

谢谢

推荐答案

使用 .siblings() 来找到一个类details的元素,该元素是链接的父元素的同级元素.

Use .siblings() to find an element with the class details that is a sibling of the link's parent element.

$('.item h3 a').click(function () {
    $(this).parent().siblings(".details").toggleClass("display");
});​

演示

这篇关于定位类的单个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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