[英]Read more button with jquery
I have a full the content.我有一个完整的内容。 When I click on the button, immediately all the blocks are shown completely, but I need to completely show only the block that I clicked on php
当我单击按钮时,所有块立即完全显示,但我只需要完全显示我在 php 上单击的块
<?php if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="content"><?php the_content(); ?></div>
<button class="show-more">Show more</button>
<?php endwhile; ?>
css css
.content { max-height: 20px; overflow: hidden; }
.show-more { margin-top: 15px; }
jquery jquery
jQuery(document).ready(function() {
jQuery('.show-more').click(function() {
jQuery('.content').css('max-height', 'none');
jQuery(this).remove();
});
});
When you target .content
you are selecting all elements in that class.当您以
.content
为目标时,您将选择 class 中的所有元素。 You may switch to ID selector or using.prev() to select only the previous element:您可以切换到 ID 选择器或 using.prev() 到 select 仅前一个元素:
jQuery(this).prev(".content").css('max-height', 'none');
You should also remove overflow:hidden
:您还应该删除
overflow:hidden
:
jQuery(this).prev(".content").css({'max-height':'none','overflow':'auto'});
Find the closest .content
查找最近的
.content
Try this尝试这个
jQuery(document).ready(function() {
jQuery('.show-more').click(function() {
jQuery(this).closest('.content').css({'max-height':'none','overflow':'auto'});
jQuery(this).remove();
});
});
``
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.