I'm having a scenario like multiple sections have similar functionality as defined below 

```
<html lang="en"> <head>
        <title>Test</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

        <script type="text/javascript">
        $(function(){
            $("#fav_countries_checkboxAll_option").click(function(){  
                $(".fav-color").prop('checked', 'checked');
            });
                    $("#fav_sports_checkboxAll_option").click(function(){  
                $(".fav-sport").prop('checked', 'checked');
            });

        });
        </script> </head> <body>   <h3>Favorite Countries</h3>   <a id="fav_countries_checkboxAll_option"
    href="javascript:void(0);">Select all</a>   <input type="checkbox"
    class="fav-color" name="country1" value="India">India<br/>   <input
    type="checkbox" class="fav-color" name="country2"
    value="Singapore">Singapore<br/>   <input type="checkbox"
    class="fav-color" name="country3" value="Australia">Australia<br/>  
    <input type="checkbox" class="fav-color" name="country4"
    value="Ameria">Ameria<br/>   <br/>
         <h3>Favorite Sports</h3>   <a id="fav_sports_checkboxAll_option" href="javascript:void(0);">Select
    all</a>   <input type="checkbox" class="fav-sport" name="sport1"
    value="Cricket">Cricket<br/>   <input type="checkbox"
    class="fav-sport" name="sport2" value="Tennis">Tennis<br/>   <input
    type="checkbox" class="fav-sport" name="sport3"
    value="VolleyBall">VolleyBall<br/>    </body> </html>

```

I feel like I'm duplicating the code for each section. I want like to have generic method which will handle scenario. 
How to achieve this in jquery.