Check if the selected item contains a space

I am trying to check if an element is empty.

My item might be something like

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

I 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 not find it. Anyway, can I do this? Many thanks!

+4
source share
1 answer

Try using $.trim as below

 $.trim($(this).text()) === '' 
+9
source

Source: https://habr.com/ru/post/1495643/


All Articles