Guest User

Untitled

a guest
Dec 28th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function addLocation() {
  2.         var a = $( '.add-location' );
  3.  
  4.         a.on('click', function() {
  5.             var item       = $('.location-counter');
  6.             var counter    = item.length;
  7.             var newCounter = new Number(counter + 1);
  8.             var cloned     = $('.location-' + counter).clone().attr('class', 'location-counter inputs location-' + newCounter).fadeIn('slow');
  9.            
  10.             var checkboxId   = $(this).attr('id');
  11.             var inputName    = $(this).attr('name');
  12.             var labelFor     = $(this).attr('for');
  13.  
  14.             cloned.find('input[type="checkbox"]').each(function() {
  15.                 var checkboxId   = $(this).attr('id');
  16.                 $(this).attr('id', checkboxId + '-' + newCounter);
  17.             });
  18.  
  19.             cloned.find('input').each(function() {
  20.                 var inputName    = $(this).attr('name');
  21.                 $(this).attr('name', inputName + '-' + newCounter);
  22.             });
  23.  
  24.  
  25.             cloned.find('label').each(function() {
  26.                 var labelFor     = $(this).attr('for');
  27.                 $(this).attr('for', labelFor + '-' + newCounter);
  28.             });
  29.  
  30.             $('.location-' + counter).after(cloned);
  31.         });
  32.     }
  33.  
  34.     addLocation();
Advertisement
Add Comment
Please, Sign In to add comment