change the background color of class
How to make that when you click on class fon of box1, the background color of class sun of box1 must to changes, and when you click on class fon of box2, the background color of class sun of box 2 must to changes. At the moment, the background color of boxes 1 and 2 is changing, although only click on one of the boxes.
- <style>
- .container {
- display: flex;
- }
- .sun{
- margin-top: -6rem;
- margin-left: auto;
- margin-right: auto;
- width: 10rem;
- height: 14rem;
- background-color: orange;
- }
- .fon{
- background-color:green;
- width: 9rem;
- height: 9rem;
- }
- .d19{
- background-color:blue;
- width: 10rem;
- height: 11rem;
- }
- h1{padding-top:5rem;
- }
- </style>
- <script src="jquery-3.4.1.js"></script>
- </head>
- <body >
- <div class='container'>
- <div class='sun'>
- <div class="d19" >
- <div class='fon'>
- <h1>1 box</h1>
- </div>
- </div>
- </div>
- <div class='sun'>
- <div class="d19" >
- <div class='fon'>
- <h1>2 box</h1>
- </div>
- </div>
- </div>
- </div>
- <script>
- $( document ).ready(function(){
- $('.fon').mouseup(function() {
- $('.sun').css({'background-color':'yellow'});
- });
- });
- </script>