Question: I've found plenty of other topics similar to this one, but I they are all slightly unique... so here goes:

I'm trying to construct an IF statement based on whether an element is empty. However, since the CMS I'm working with will still output empty space, my IF statement needs to be able to recognize empty white space and empty children elements as still "empty" as far as the parent element is concerned.

This is the code I have - and it works well in modern browsers, but it's **not working IE 7/8**. I've read that there **might be issues with "trim" in IE**?

Any ideas on an alternative solution that will work with IE?

```
$('.items').each(function() {
    if ($(this).find('.the-element-to-check-for-emptiness').html().trim()) {
        $(this).css('display', 'block');
    }
});

```

Basically, I'm hiding all ".items" by default, and then if their "the-element-to-check-for-emptiness" element has any content I un-hide the item.

Any input is appreciated,
Thanks!

UPDATE

After the insight from James I've updated my code to change the call to "trim" but now the IF statement appears to always evaluate to false no matter what. Any ideas?

```
$('.items').each(function() {
    if ($(this).find('.the-element-to-check-for-emptiness').html()$.trim()) {
        $(this).css('display', 'block');
    }
});

```

Answer: 
IE doesn't have `trim`, use jquery's `$.trim()` instead.

<http://api.jquery.com/jQuery.trim/>

```
$.trim($(this).find('.the-element-to-check-for-emptiness').html())

```
Assuming that the CMS is using non-breaking spaces, I would use a regular expression to see if the trimmed. I would recommend this:

```
$('.items').each(function() {
   var val = $(this).find('.the-element-to-check-for-emptiness').html();
   var r = new RegExp('^((&nbsp;)|\\s)*$');
   if (!r.test(val)) {
     $(this).css('display', 'block');
   }
});

```

The regex will find any whitespace or non-breaking space and return true. Therefore, we negate it to find if there is anything else in the element.