我有一个博客文章页面"阅读更多/阅读更少"每个帖子的切换按钮。
我想隐藏" a.wpex-link"如果" .wpex_div p"是空的。问题是需要选择其父/最近链接,因为所有帖子都具有相同的类。
<a onclick="wpex_toggle(548787318, 'Read more', 'Read less'); return false;" class="wpex-link" href="#" target="_blank">Read less</a>
<div class="wpex_div" id="wpex548787318" style="display: block;">
<div class="sidebar-content"></div>
<p></p>
</div>
答案 0 :(得分:1)
$('.wpex_div:has(p:empty)').prev('.wpex-link').hide();
$('.wpex_div:has(p:empty)').prev('.wpex-link').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<a onclick="wpex_toggle(548787318, 'Read more', 'Read less'); return false;" class="wpex-link" href="#" target="_blank">Read less</a>
<div class="wpex_div" id="wpex548787318" style="display: block;">
<div class="sidebar-content">The p element is empty. That is why the 'Read less' anchor is not displaying</div>
<p></p>
</div>