我正在尝试检查元素是否为空。
我的元素可能是这样的
<table>
<td> </td>
<td> </td>
<td> </td>
<td>text</td>
</table>
我试过:
$('table td').each(function(){
if($(this).is(':empty')){
console.log('found;)
}
})
和
$('table td').each(function(){
if($(this).html()==' '){
console.log('found')
}
})
但是我好像找不到。无论如何我可以做到这一点?非常感谢!
最佳答案
尝试像下面这样使用 $.trim
,
$.trim($(this).text()) === ''
关于jquery - 检查所选元素是否包含空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18092966/