0

I'm working on wordpress template where div.post-thumb is empty but have dynamic white spaces.

<div class="post-thumb">    </div>
<div class="post-text"></div>

I'm using following script to detect if div.post-thumb is empty.

$('.post-thumb').each(function(){
if ($(this).html()=='') $('.post-text').css('marginLeft','50px');
}); 

Problem with this script is "Dynamic white spaces within div.post-thumb"

How to get rid of this issue? Is there any other way to detect if div is empty excluding white spaces?

1 Answer 1

5

You can use the jQuery trim function to remove whitespace:

$('.post-thumb').each(function(){
    if($.trim($(this).html()) == '') $('.post-text').css('marginLeft','50px');
}); 

trim removes all spaces, new lines and tabs from the beginning or end of a string. See the jQuery docs for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.