简体   繁体   English

特定于所选清单的Onclick显示隐藏的Div

[英]Onclick Show Hidden Div specific to the Listing selected

I have a list of data which is collected from the database. 我有一个从数据库收集的数据列表。

I have added a Div with a "Read More" label and another div which holds the content and is hidden. 我添加了一个带有“ Read More”标签的Div和另一个保存内容并被隐藏的div。

When the user clicks on the "read More" text the Content div with show up. 当用户单击“阅读更多”文本时,将显示Content div。

Here is my current code below: 这是我当前的代码如下:

<script>
    $(document).ready(function(){

        $(".readmore").click(function() {
            $('.readmecontent').show();
        });
    });
</script>

//THE HTML .. Note: Content will be added via php but hardcoded now ... // HTML ..注意:内容将通过php添加,但现在已进行硬编码...

echo '<div class="readmore">Read more...</div>';
echo '<div class="readmecontent" style="display:none;">Read Me Content Here</div>';

All the above works but the problem is that the "readmore" class currently opens all "readmecontent" classes. 以上所有方法均有效,但问题在于“ readmore”类当前打开了所有“ readmecontent”类。

I need it to just show the "readmecontent" DIV that applies to the "readmore" class that has been clicked. 我只需要显示适用于已单击的“ readmore”类的“ readmecontent” DIV。

I cannot use ID's because the listing is created dynamially. 我无法使用ID,因为该列表是动态创建的。

How can I do this? 我怎样才能做到这一点?

使用的实例, this找到下一个元素:

$(this).next('.readmecontent').show();

this solution doesn't need you to hold an instance 该解决方案不需要您持有实例

$(".readmore").click(function() {
    $('.readmecontent:not(.readmecontent.visible)').eq(0).show().addClass('visible');
});

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

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