简体   繁体   English

标签为空时如何隐藏?

[英]How can I hide tabs when they are empty?

I want to create a function where I will be able to hide a tab if it's empty, based on tab's content-id .我想创建一个 function ,如果它是空的,我将能够根据标签的content-id隐藏一个标签。

 $(function() { $('.bdt-switcher-item-content').children().each(function() { if ($(this div).is(':empty')) $('div[content-id="' + $(this).attr('content-id') + '"]').hide(); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="bdt-switcher-wrapper"> <div id="bdt-tab-content-a49ef84" class="bdt-switcher bdt-switcher-item-content"> <div content-id="tab-1" class=""> <div></div> </div> <div content-id="tab-2" class="bdt-active"> <div>I am tab #2 content</div> </div> <div content-id="tab-3" class=""> <div> I am tab #3 content.</div> </div> </div> </div>

I think you wrong here:我认为你在这里错了:

$(this div)

See my example, you must declare what you want so in this case "div" before use this.看我的例子,你必须在使用它之前声明你想要的东西,在这种情况下是“div”。 Work example:工作示例:

 $(function() { $('.bdt-switcher-item-content').children().each(function() { if ($("div",this).is(':empty')) $('div[content-id="' + $(this).attr('content-id') + '"]').hide(); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="bdt-switcher-wrapper"> <div id="bdt-tab-content-a49ef84" class="bdt-switcher bdt-switcher-item-content"> <div content-id="tab-1" class=""> <div></div> </div> <div content-id="tab-2" class="bdt-active"> <div>I am tab #2 content</div> </div> <div content-id="tab-3" class=""> <div> I am tab #3 content.</div> </div> </div> </div>

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

相关问题 标签文本为空时如何隐藏Div? - How can I hide a Div when text of a label is empty? Bootstrap可切换标签。 将鼠标悬停在`.nav-tabs&gt; li`上方时如何显示.tab窗格内容,然后在鼠标离开时隐藏该内容? - Bootstrap Togglable tabs. How can I show the .tab-pane content when I hover over the `.nav-tabs > li`, then hide the content when the mouse leaves? 我如何制作将在表为空时隐藏表的jQuery脚本? - How can I make jquery script that will hide table when table is empty? 消息字符串为空时如何隐藏 div? (特别是:SPRING_SECURITY_LAST_EXCEPTION.message) - How can I hide a div when the message string is empty? (specifically: SPRING_SECURITY_LAST_EXCEPTION.message) html5 视频标签在没有上传视频时显示一个空的视频框。 我怎样才能隐藏这个空盒子? - html5 video tag displays an empty video box when no video is uploaded. How can I hide this empty box? 显示某些选项卡时如何隐藏元素 - How to hide an element when certain tabs is shown 隐藏空标签如果它没有内容 - Hide empty tabs If it has no content 内部div为空时如何隐藏div? - How do I hide a div when an inside div is empty? 如何使用 jQuery 隐藏空的 html 表格单元格? - How can I hide empty html table cells with jQuery? 如果 dd 有空值,我如何隐藏 dt - How can i hide dt if dd got empty value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM