Here is the structure of the tabs. Without being able to edit the HTML, is it possible to hide the tab and contents when the content is empty? I have provided minimal jQuery below, but I’m unable to bend it to my will and confused. I appreciate any assistance.
<div class="et_pb_module et_pb_tabs et_pb_tabs_0_tb_body et_slide_transition_to_1 et_slide_transition_to_2 et_slide_transition_to_3 et_slide_transition_to_5 et_slide_transition_to_0">
<ul class="et_pb_tabs_controls clearfix">
<li class="et_pb_tab_0_tb_body et_pb_tab_active" style="height: 50.5938px;"><a href="#">Description</a></li>
<li class="et_pb_tab_1_tb_body" style="height: 50.5938px;"><a href="#">Specifications</a></li>
<li class="et_pb_tab_2_tb_body" style="height: 50.5938px;"><a href="#">Videos</a></li>
<li class="et_pb_tab_3_tb_body" style="height: 50.5938px;"><a href="#">Downloads</a></li>
<li class="et_pb_tab_4_tb_body" style="height: 50.5938px;"><a href="#">What's Included</a></li>
<li class="et_pb_tab_5_tb_body" style="height: 50.5938px;"><a href="#">Compare Similar</a></li>
</ul>
<div class="et_pb_all_tabs">
<div class="et_pb_tab et_pb_tab_0_tb_body clearfix et_pb_active_content et-pb-active-slide" style="z-index: 1; display: block; opacity: 1;">Tab 1 Product Description </div>
<div class="et_pb_tab et_pb_tab_1_tb_body clearfix" style="z-index: 1; display: none; opacity: 0;"> Tab 2 content </div>
<div class="et_pb_tab et_pb_tab_2_tb_body clearfix" style="z-index: 1; display: none; opacity: 0;"> Tab 3 content </div>
<div class="et_pb_tab et_pb_tab_3_tb_body clearfix" style="z-index: 1; display: none; opacity: 0;"> Tab 4 content </div>
<div class="et_pb_tab et_pb_tab_4_tb_body clearfix" style="z-index: 1; display: none; opacity: 0;"> Tab 5 content </div>
<div class="et_pb_tab et_pb_tab_5_tb_body clearfix" style="z-index: 1; display: none; opacity: 0;"> Tab 6 content </div>
</div>
</div>
<script>
$(document).ready(function() {
$(".et_pb_tabs_controls").each(function() {
var $tabclass = $(this).addClass('et_pb_tab');
var $txt = $(this).text();
if ($txt == "") {
$('a[data-target=#'+$tabclass+']').closest('div').hide();
}
});
});
</script>
2
Answers
You mean hide the link AND div if the link is empty?
If we just hide the link, then we cannot navigate to the div anyway.
In any case here is the code you need to do either or both
Not easy to understand what content you want to check and hide.
Your
a
tag doesn’t have thedata
property.If you want to check the content of the
li
you need to iterate over it and not overul
You could use a
data-target
on theli
to identify the class of thediv
you want to hide.So, just check the content of the element, get the element mentioned in
data-target
and hide them as you did.