G
G
GitFront2020-04-17 18:10:39
JavaScript
GitFront, 2020-04-17 18:10:39

How to set a condition for block height?

How to add a class if the height of the sub-menu block is more than 140px and not add a class if it is less?

<ul class="menu">
  <li>144</li>
    <ul class="sub-menu">
      <li>123</li>
      <li>123</li>
      <li>123</li>
      <li>123</li>
      <li>123</li>
      <li>123</li>
      <li>123</li>
      <li>123</li>
  </ul>
   <li>155</li>
    <ul class="sub-menu">
      <li>123</li>
      <li>123</li>
  </ul>
</ul>

$( document ).ready(function() {
height = $('.sub-menu').height();
  if (height > 120) {  
    $('.sub-menu').addClass('scroll')
  }
else{
     $('.sub-menu').removeClass('scroll')
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kuzyakin, 2020-04-18
@GitFront

like this: https://jsfiddle.net/f54bhpw8/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question