如何隐藏一个空的div以及与其关联的另一个可能为空或不为空的div?
我有一个名为“哲学气泡”的语音气泡,它只是一个看起来像引用气泡的 div,共享点控件填充了气泡的内容,但有时气泡可能没有任何文本,需要隐藏。不仅仅是气泡,还有下面的文字,就像“Mr.”。 X 说的“应该隐藏,因为气泡是空的”。 jquery中是如何实现的?
<div class="philosophy-bubble">Quote goes here
</div>
<span class="credit">
Quoter..
</span>
I have a speech bubble called philosophy bubble which is just a div styled to look like a quote bubble and the sharepoint control is what fills up the content of the bubble but sometimes the bubble may not have any text and needs to be hidden. Not just the bubble but also the text below which is like 'Mr. X's saying' should be hidden since the bubble is empty. How is is achieved in jquery?
<div class="philosophy-bubble">Quote goes here
</div>
<span class="credit">
Quoter..
</span>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您只想隐藏其中没有文本的气泡,您可以这样做:
Assuming you only want to hide the bubbles that have no text in them, you could do it this way:
如果您有权访问 HTML,则可以将
和
包装在父
中标签。然后可以隐藏父级。
$('.philsophy-bubble').parent().hide()
如果您有权访问 jQuery(我看到您标记了此 jQuery),您可以使用
.next()
函数获取下一个兄弟(垂直)。类似...
$('.philosophy-bubble').hide().next().hide();
If you have access to the HTML, you could wrap both the
<div>
and<span>
in a parent<div>
tag. The parent could then be hidden.$('.philsophy-bubble').parent().hide()
If you have access to jQuery (I see you tagged this jQuery), you can use the
.next()
function which gets the next sibling (vertically).Something like...
$('.philosophy-bubble').hide().next().hide();