javascript - 找到子 H3 并检查是否有值
问题描述
我希望用来jQuery
查看一堆<div>
具有相同类名的元素,并检查h3
这些<div>
元素中是否有任何内容。我在想这会起作用(如下所示),但它不是......我做错了什么?
$('.wrapperDIV').each(function (i) {
if( $(this).closest('h3').val().length == 0 ) {
$(this).addClass('.hideME');
}
});
标记是:
<div class="wrapperDIV">
<span class="ItemNo">5.</span>
<a href="#" title="Read more about "><img src="" title="" alt=""></a>
<h3></h3>
<div class="composer-button">
<a href="#" class="read-more" title="Read more about ">Read more</a>
</div>
</div>
解决方案
:empty
您可以通过使用伪类单独使用 CSS 来实现此效果:
.wrapperDIV h3:empty {
display: none;
}
延伸阅读:
推荐阅读
- google-play - 谷歌游戏控制台,内部测试仍然出现(对我来说!)
- linux - 使用 linux 中另一个文件的输入条件过滤和提取表的各个部分
- r - ggplot 的问题
- csh - xterm 中命令的退出代码
- reactjs - 通过功能组件导入和导出多个组件
- javascript - 错误:无法在默认位置找到 env 文件 (./.env,./.env.js,./.env.json)
- bash - 如何回显关联数组bash的关联部分
- python - TensorFlow:TypeError:int() 参数必须是字符串、类似字节的对象或数字,而不是“NoneType”
- google-apps-script - 无法授予最终用户使用带有 Bearer 令牌的 Google Apps Script Web App 的权限,为什么?
- vue.js - 在 Vue 中将带有方法的对象存储在哪里?