检查所选元素是否包含空格

时间:2013-08-07 01:00:07

标签: jquery html

我正在尝试检查元素是否为空。

我的元素可能类似于

<table>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>text</td>
</table>

我试过了:

$('table td').each(function(){
  if($(this).is(':empty')){
    console.log('found;)
  }
})

$('table td').each(function(){
  if($(this).html()=='&nbsp;'){
    console.log('found')
  }
})

但我似乎无法找到它。无论如何,我能做到这一点?非常感谢!

1 个答案:

答案 0 :(得分:9)

尝试使用下面的$.trim

$.trim($(this).text()) === ''
相关问题