How to check the size of a div and adjust it by jquery?

Asked

Viewed 339 times

1

How can I check the size of a div with jquery? The timing of that div is automatic, but I’d like to limit your endurance. I am assigning a class to this element, because it is inside a loop of my server application, soon will repeat. The logic would be as follows: If it is less than 200px, I would like to equal 200px.

1 answer

1


You can get the height of div using $(seletor).outerHeight(true). This method takes the full height of the element, including padding and border, if there is any.

In relation to equalizing the height if it is less than 200px, you can put code down after the loop of your server application (changing the value ".div" the class of elements in question):

<script>
$(".div").each(function(){
   $(this).outerHeight(true) < 200 ? $(this).css('height','200px') : 0;
});
</script>
  • But I had to run to the css that was better... I know it has nothing to do with the question, but the css gave me the option to play both minimum value and maximum value. In query you could too, but CSS is lighter for this case. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.