Identifying an empty text node with jQuery + Javascript

Posted by b. e. hollenbeck on Stack Overflow See other posts from Stack Overflow or by b. e. hollenbeck
Published on 2012-09-01T03:36:34Z Indexed on 2012/09/01 3:37 UTC
Read the original article Hit count: 318

Filed under:
|
|

You'd think this was easy - but I'm having the hardest time with it.

Here's what I'm trying to identify:

<span class="cw-value-one"></span>

Here's what I'm using so far:

    $('span.cw-value-one').each(function(){
        var textNode = $(this).text();
        var type = typeof textNode;
        var len = textNode.length;
        if($(this).is(':empty')){
            $(this).siblings('span.cw-value-two').css({"position": "relative", "left": "1em"});
        }
    });

Ok, so textNode = "", type = string and len = 1 - none of which is helpful in identifying an empty text node, since a has a type of string and length of 1. The jQuery .is(':empty') is not working either.

So whow do you identify an empty text node in JQuery or plain ol' Javascript?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery