2016-08-02 46 views
0

我正在使用一個函數來隱藏空容器,但它不能在一個部分工作。jQuery函數不隱藏部分

下面是代碼:

$('.lmla-hidden').each(function() { 
     if ('' === $.trim($(this).text())) { 
     $(this).hide(); 
     } 
    }); 

這是被施加在那裏:

<section class="section-wrapper-projects lmla-hidden"> 

      <h2 class="section-title lmla-hidden"><?php echo CFS()->get('course_details_title_project'); ?></h2> 

      <div class="projects-description lmla-hidden"> 
         <?php echo CFS()->get('design_cycle'); ?> 
        </div> 

      <div class="single-project-wrapper lmla-hidden"> 
         <p class="project-title lmla-hidden"><?php echo CFS()->get('project_title'); ?></p> 

         <div class="project-image lmla-hidden"><img src="<?php echo CFS()->get('project_image'); ?>"></div> 

         <style> .project-link-btn a {color: <?php echo CFS()->get('link_text_colour'); ?>;} </style> 
         <style> .project-link-btn {background: <?php echo CFS()->get('project_link_colour'); ?>;} </style> 

         <div class="project-link-btn lmla-hidden"><?php echo CFS()->get('projects_link'); ?></div> 

        </div> 

     </section> 

仍被施加到節中的填充底屬性。

+0

'lmla-hidden'有帶班'lmla-hidden'你可以指定你指的是哪個人物這麼多的元素呢? – guradio

+0

只是把一個調試器放在函數內部,並試圖找出爲什麼文本不是空的,首先要自己動手。 – jarvanJiang

+0

具體而言,它是節類「section-wrapper-projects」。所有其他元素在應用lmla-hidden時隱藏,只有部分保留其屬性。我認爲這可能與該功能無法隱藏部分有關。 – TomasG

回答

1

看來一切正常。

$('.lmla-hidden').each(function() { 
 
    if (!$.trim($(this).text())) { 
 
    $(this).hide(); 
 
    } 
 
});
.project-link-btn a { 
 
    color: red; 
 
    background: black; 
 
} 
 

 
.project-link-btn { 
 
    background: black; 
 
} 
 

 
.lmla-hidden { 
 
    border: 1px solid black; 
 
    margin: 5px; 
 
    padding: 3px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<section class="section-wrapper-projects lmla-hidden"> 
 

 
    <h2 class="section-title lmla-hidden">Test</h2> 
 

 
    <div class="projects-description lmla-hidden"> 
 
    Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? 
 
    </div> 
 
    
 
    <div class="projects-description lmla-hidden"> 
 
    <!-- An empty element will be hidden --> 
 
    </div> 
 

 
    <div class="single-project-wrapper lmla-hidden"> 
 
    <p class="project-title lmla-hidden"> 
 
     Test 
 
    </p> 
 

 
    <div class="project-image lmla-hidden"><img src="some-img.jpg"></div> 
 

 
    <div class="project-link-btn lmla-hidden"> 
 
     <a href="#">qwerty</a> 
 
    </div> 
 

 
    </div> 
 

 
</section>