toggle function to limited tags on click event

toggle function to limited tags on click event

I have 10 boxes, I have added toggle functions to it to select the box by adding class 'active'. I want to let user to select only 6 boxes. When user selects 6 boxes it not letting to select others which is working fine. My problem is I want to change my selection again but it is not letting me to do that. Below is code:

  1. $('a').click(function(){
  2.       if($('.active').length < 6) {
  3.             $(this).toggleClass('active')
  4.       }
  5. })
I want to change my selection, please help!