removing disabled attribute from fieldset

removing disabled attribute from fieldset

Hi, i have a bunch of fields in a field set which i want to disabled, if someone wants to edit the form they simply click the edit button and it unlocks the fields for them to edit. I am disabling the fields by adding the disabled attribute to the field set itself. I also need to remove the top margin from my form groups when the inputs are enabled. This is my jquery code so far which i can't get to work.

  1. <script>
  2. $(document).on('click' function (event) {
  3. event.preventDefault();
  4.     var $btn = $(this);
  5.     var $container = $(this).closest('.details-container');
  6.     var $fieldset = $container.find('fieldset');
  7.     $fieldset.removeAttr("disabled");
  8.     $('.form-group.disabled').removeClass('disabled');
  9. });
  10. </script>
My original code looked liked like the below - but i wanted to make it cleaner rather than duplicating the code over again.

  1. $("#ContactAddressEdit").click(function(event){
  2. event.preventDefault();
  3. $('fieldset').removeAttr("disabled");
  4. $('.form-group.disabled').removeClass('disabled');
  5. });
  6. $("#ContactBillingEdit").click(function(event){
  7. event.preventDefault();
  8. $('fieldset').removeAttr("disabled");
  9. $('.form-group.disabled').removeClass('disabled');
  10. });
  11. $("#ContactPostagegEdit").click(function(event){
  12. event.preventDefault();
  13. $('fieldset').removeAttr("disabled");
  14. $('.form-group.disabled').removeClass('disabled');
  15. });

A fiddle can be found here