Add a class on click to a link

Add a class on click to a link and remove the class when clicking another link with JQuery

    <script>   
//to add class on active
    $("a").click(function(){
   $("a.active").removeClass("active");
   $(this).addClass("active");
    });
    </script>