user2946744
user2946744

Reputation: 21

Trying to make two heights equals

I already searched for this here, but I didn't find anything that helped me out.

I want to make the height of a the "widgets" always the same as the "posts"s height. In this case the "posts"s is always taller than "widgets"s.

This is what I have:

       $(document).ready(function(){

            var widgets = $('.widgets-wrapper').height();
            var posts = $('#posts-wrapper').height();

            if ( widgets < posts ) {
                widgets == posts
            });

        });

Please tell me if I did something wrong,

Thanks!

Upvotes: 0

Views: 28

Answers (2)

charlietfl
charlietfl

Reputation: 171689

If posts is always taller you don't need to test anything, just set height to match

$('.widgets-wrapper').height($('#posts-wrapper').height());

Upvotes: 1

Jordan Davis
Jordan Davis

Reputation: 1327

You are getting the variable, but you need to actually update the object.

Also

widgets == posts

only checks if widgets is equal to posts, it doesn't change widgets. Try:

 $(document).ready(function(){

            var widgets = $('.widgets-wrapper').height();
            var posts = $('#posts-wrapper').height();

            if ( widgets < posts ) {
                widgets = posts;
                $('.widgets-wrapper').height(widgets);
            });

        });

This is still pretty clumsy, but it should work.

Upvotes: 1

Related Questions