I have a scenario where there is an unordered list containing 1 to 3 items within it. Unfortunately, this list is situated inside a fixed-height div
with overflow: hidden
.
<div id="container">
<ul id="tweets">
<li>
Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Etiam est nisi, congue
id pulvinar eget.
</li>
<li>
Donec nisi dolor, molestie quis varius
a, dictum vel nunc. Morbi odio lorem,
viverra eu semper eu.
</li>
<li>
Mollis ac lorem. Aenean consequat
interdum mi, nec vestibulum metus mollis
non. Curabitur sed.
</li>
</ul>
</div>
If the list contains exactly 3 items, the line-height must not exceed 1em to fit perfectly in the container. If less than three items are present, the line-height can be up to 1.5em to align with the overall site design.
I am attempting to use jQuery to dynamically adjust the line-height.
var tweet_len = $("#tweets > li").size();
if (tweet_len == 0) {
// append a message indicating no tweets available
// (this message resembles a tweet and has line-height: 1.5em)
} else if (tweet_len > 0 && tweet_len < 3) {
$("#tweets li").each(function(){
$(this).css("line-height: 1.5em");
});
}
I attempted to utilize the code above (lines 6-8) but encountered issues. (I suspect I lack a full grasp on how to use .each().)
Can you provide guidance on the correct code for lines 6-8 to update the line-height to 1.5em?