Solved

jQuery: Test if height greater than min-height

Posted on 2011-03-18
1
938 Views
Last Modified: 2012-06-21
How can I test if the actual height of a div is greater than its minimum height?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<style type="text/css">

#d1, #d2 {
width: 120px;
min-height: 200px;
border: 1px solid red;
margin: 20px;
}

</style>
</head>
<body>

<div id="d1">
Hello World
</div>

<div id="d2">
Tdsafads jkadsh kdjsh jkdash kads hakdjsh adkjs hdsjk hafdsj fads jkadsh kdjsh jkdash kads hakdjsh adkjs hdsjk hafdsj fads jkadsh kdjsh jkdash kads hakdjsh adkjs hdsjk hafdsj 
Tdsafads jkadsh kdjsh jkdash kads hakdjsh adkjs hdsjk hafdsj fads jkadsh kdjsh jkdash kads hakdjsh adkjs hdsjk hafdsj fads jkadsh kdjsh jkdash kads hakdjsh adkjs hdsjk hafdsj 
</div>

<script type="text/javascript">

alert('jQuery should be used to test if the height of #d1 height is greater than its min-height')
alert('jQuery should be used to test if the height of #d2 height is greater than its min-height')

</script>

</body>
</html>

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
Comment Utility
var d1 = $("#d1");
if ( d1.css("min-height")  < d1.css("height") )
or
if ( d1.css("min-height")  < d1.height() )
or
if ( d1.css("min-height")  < d1.innerHeight() )
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now