简体   繁体   English

显示/隐藏多个Divs

[英]Show/Hide Multiple Divs

I am trying to trigger a show/hide of one div at a time. 我正在尝试一次触发一个显示/隐藏一个div。

What is happening is that all the divs (.shareLink) are opening at the same time. 正在发生的是所有div(.shareLink)都同时打开。

Below is my jQuery: 下面是我的jQuery:

$(document).ready(function(){
$(".shareLink").hide();
$("a.trigger").click(function(){
$(".shareLink").toggle("400");
return false;
});
});

Below is my HTML: 以下是我的HTML:

<dl class="links">
    <dd>content</dd>
    <dt class="description">content</dt>
    <ul class="tools">      
        <li><a class="trigger" href="#">Share Link</a></li>
    </ul>
</dl>
<div class="shareLink">
<?php print check_plain($node->title) ?>
</div>

Any help with the above problem would be much appreciated. 任何有关上述问题的帮助将不胜感激。

Cheers. 干杯。

Based on your HTML, you need to do this: 根据您的HTML,您需要执行以下操作:

$(function() {
    $("div.shareLink").hide();
    $("a.trigger").click(function(){
        $(this).parents('dl.links').next('div.shareLink').toggle(400);
        return false;
    });
});

This walks up to the parent DL and then moves over to the next shareLink div and toggles it. 这将转到父DL,然后移至下一个shareLink div并进行切换。

$(".shareLink").toggle("400");

Refers to any div on the page with a class of ".shareLink". 用“ .shareLink”类引用页面上的任何div。

You will need to find a way to distinguish the specific div you want to show. 您将需要找到一种方法来区分要显示的特定div。

You might want to try: 您可能要尝试:

$(document).ready(function(){
    $(".shareLink").hide();
    $("a.trigger").click(function(e){
        e.preventDefault();
        $(this).next().toggle("400");
    });
});

The answer is it depends on the structure of your document. 答案是,这取决于文档的结构。 Here is a sample of something that will work with the above function. 这是将与上述功能配合使用的示例。

<a class="trigger">click here</a>
<div class="shareLink">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM