How to check if element have any text

Posted by user3611403 on Stack Overflow See other posts from Stack Overflow or by user3611403
Published on 2014-05-27T09:17:45Z Indexed on 2014/05/27 9:25 UTC
Read the original article Hit count: 184

Filed under:
|
|

How can I check, if element does have any text? I have found some code, but it does not work. I need to do something like this: If element has text, write this, if not, write something else.

    if (!$('.flexslider .item:first p').text().trim().length) {
        var text = $(this).text();
        $('.text-anim-sphone').html(text);
    }
    else {
        $('.text-anim-sphone').html('welcome');
    }

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about if-statement