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

1

How can I check the size of a div with jquery? The height of this div is automatic, but I would like to limit its size. I'm assigning a class to this element, since it's within a loop of my server application, so it will repeat itself. The logic would be as follows: If it is less than 200px, I would like to equal 200px.

    
asked by anonymous 08.11.2017 / 20:58

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 any.

Regarding to match the height if it is less than 200px , you can put code below the loop of your server application (changing the value ".div" by the class of the elements in question) :

<script>
$(".div").each(function(){
   $(this).outerHeight(true) < 200 ? $(this).css('height','200px') : 0;
});
</script>
    
08.11.2017 / 21:08