Prompt why delegation does not work? There is a block with a class .team-item. It is necessary that when you hover on any part of it, the text changes color. The text has a class .name-description. The js and jq files are connected at the end of the body. The js file is written like this:

$('.team-item').on('hover', function() { $('.name-description').css("color", "#00e0d0"); }); 
  • add html markup. And add: what and where are you delegating here - Grundy
  • I do not see delegation in your code. - Jean-Claude
  • 2
    Here .team-item does not delegate anything. Delegation is achieved by passing the second argument with the CSS selector, which will be the target of the handler. And at the head of the corner ( $(...).on(...); ) should be the parent. - user207618
  • "The js and jq file are connected at the end of the body." - in what order? - Igor

1 answer 1

Read doc. http://api.jquery.com/hover/

Solution 1:

 $('.team-item').hover( function() { $('.name-description').css("color", "#00e0d0"); }, function(){ $('.name-description').css("color", "inherit"); } ); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="team-item">Hover it</div> <div class="name-description">Change color</div> 

Solution 2 jsbin:

 $('.team-item').on({ mouseenter: function() { $('.name-description').css("color", "#00e0d0"); }, mouseleave: function() { $('.name-description').css("color", "inherit"); } }); 
  • it is impossible - what exactly is it ? - Grundy
  • and why solution 2 on jsbin, and not the same in the snippet? - Grundy
  • 3
    @Grundy, I want it so! - HamSter
  • one
    Ideally, it is better to use the built-in snippet so that with jsbin, the example of the solution is not lost. Well, for consistency, so that everything is the same - Grundy
  • one
    @Grundy, and I love diversity, but I’ll take your advice for the future! - HamSter