How to set the condition for the height of the block?

How to add a class if the height of the block sub-menu 140px more and not add the class if less?
<ul class="menu">
the <li>144</li>
 <ul class="sub-menu">
the <li>123</li>
the <li>123</li>
the <li>123</li>
the <li>123</li>
the <li>123</li>
the <li>123</li>
the <li>123</li>
the <li>123</li>
</ul>
the <li>155</li>
 <ul class="sub-menu">
the <li>123</li>
the <li>123</li>
</ul>
</ul>

$( document ).ready(function() {
height = $('.sub-menu').height();
 if (height > 120) { 
$('.sub-menu').addClass('scroll')
}
else{
$('.sub-menu').removeClass('scroll')
}
April 19th 20 at 12:34
1 answer
April 19th 20 at 12:36

Find more questions by tags jQueryJavaScript