Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the selected element contains white space

Tags:

html

jquery

I am trying to check if the element is empty.

My element could be something like

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

I have tried:

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

and

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

but I can't seem to find it. Anyway I can accomplish this? Thanks a lot!

like image 701
FlyingCat Avatar asked Jan 12 '23 17:01

FlyingCat


1 Answers

Try using $.trim like below,

$.trim($(this).text()) === ''
like image 118
Selvakumar Arumugam Avatar answered Jan 21 '23 21:01

Selvakumar Arumugam