2

So I have a task at school and have no idea how to solve it. Please please please help. HTML and CSS are given and cannot be edited at all. Everything needs to be done in JS. Here is the task:

We have a list of persons. We need to add two persons to the top of the existing list (see below), and three persons to the bottom of the list. Then, need to create two events:

  1. A click on a person's name should decrease visibility to 20%, clicking it one more time should return the opacity to 100%.

  2. A double click should result in highlighting a person's name with a green color.

    <style>     
        .persons li { list-style-type: none; opacity: 1; }
        .persons li a { color: black; text-decoration: none; }
        .persons li.closed { opacity: 0.2; }
        .persons li.alt a { color: green; } 
    </style>
    

<html>
    <head></head>
    <body>
        <ul class="persons">    
            <li><a href="#">Tom</a></li>
            <li><a href="#">Jerry</a></li>  
       </ul>    
    </body>
</html>
user1506104
  • 6,554
  • 4
  • 71
  • 89
markytom
  • 29
  • 2
  • 1
    Tip: try click,dblclick event in jQuery. Toggle closed, alt classes in the event handler respectively. – K K Oct 16 '17 at 06:18
  • @markytom Check my answer – SilverSurfer Oct 16 '17 at 07:24
  • In summary, this is the solution: $(document).ready(function() { $(".persons").prepend("
  • 1
  • 2
  • "); $(".persons").append("
  • 3
  • 4
  • 5
  • "); $(document).on("click", ".persons li", function() { $(this).toggleClass("closed"); }); $(document).on("dblclick", ".persons li", function() { $(this).toggleClass("alt"); }) }); – markytom Oct 16 '17 at 17:44