I need to make sure that when a particular class is added to a specific block, I add another class to a specific block.

if ($("#block_for_scroll").hasClass("style")) { $('body').addClass("111") } 

I thought so, but it does not work. Just the first class is added when scrolling and you need to add another after adding the first class. How to implement it?

  • rather, the is () method returns boollean - Jean-Claude

1 answer 1

hasClass filtering method, you need a method that returns a boolean - is() .

 $(function() { if ($('#block_for_scroll').is('.style')) { $('body').addClass("active"); } }); 
 .active { background-color: #3c3; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <body> <div id="block_for_scroll" class="style"></div> </body> 

  • It does not work, the class does not hang on the body, I add a class when scrolling, and I need to make it so that when the first class was added during the scroll, another one was added to the body - User
  • @ User what is not working? This was an example, corrected with the addition of the body class. - Jean-Claude