从我的支票,你的代码应该做工精细;
$('#trim').click(function(){
\t jQuery('.course p').filter(function() {
\t
\t return $.trim($(this).text()) === ''
\t
\t }).remove();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="course" >
<p style="border:solid 1px red; margin-bottom:10px"> </p>
<p style="border:solid 1px red; margin-bottom:10px"> </p>
<p style="border:solid 1px red; margin-bottom:10px">this is </p>
<p style="border:solid 1px red; margin-bottom:10px"> this</p>
</div>
<button type="button" id="trim">Clear Empty Elements</button>
可以与js文件导入的方式或者也许是jQuery选择找不到元素的问题,因为它被命名错误?
或者,因为你正在使用angularjs,你应该考虑使用ng-if
ng-if="*yourDataSource*.name.indexOf(' ') !== -1"
或ES2015
的
ng-if="*yourDataSource*.includes(' ')"
莫比NG-IF?....... – madalinivascu
如果你想使用'.hide()',而不是'.remove()' – ramabarca