I agree with John Boker that you will want to use height() rather than some method that counts the number of li
s. The reason for this is that depending on the contents of the li, if it were a paragraph of text, it could have one li
but be longer than a 2 li
list with very short list items.
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla laoreet lacinia augue, a dignissim orci sagittis nec. Fusce blandit commodo felis, et aliquam orci auctor id. Vestibulum sagittis felis non urna condimentum gravida. Duis quam erat, facilisis nec rutrum sed, hendrerit non leo. Nam varius nunc eget dolor dictum sagittis rutrum sem rhoncus.</li>
</ul>
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla laoreet lacinia augue, a dignissim orci sagittis nec. Fusce blandit commodo felis, et aliquam orci auctor id. Vestibulum sagittis felis non urna condimentum gravida. Duis quam erat, facilisis nec rutrum sed, hendrerit non leo. Nam varius nunc eget dolor dictum sagittis rutrum sem rhoncus.
<ul>
<li>Short</li>
<li>Short 2</li>
</ul>
Presuming that the ul
is not floated or hidden, the method by John Boker will work. If that were the case, you would have to wait to hide or float them until their height has been measured.