jQuery code duplication, how do I write it better and cleaner?
<p>I'm having a problem with code duplication and when trying to write it cleaner it stops working, so I obviously get syntax errors. Please advise on the best ways of writing my duplication.</p>

<p>Thank You.</p>

<p>I know using classes rather than ID's as my selectors would help for starters, but the current code is written for 2 of the exact same forms on the same page. If I use classes rather than their ID's, the click functions would execute both forms rather than each form seperately. </p>

<pre><code>(function($){
$('.accordionPanelContent, #edit-actions, #webform-component-section-3--inline').hide();

var $button1 = $('&lt;button type="button" class="step-1 coda-nav-right"&gt;Find Courses Now&lt;/button&gt;'),
    $button2 = $('&lt;button type="button" class="step-2"&gt;Next&lt;/button&gt;'),
    $button3 = $('&lt;button type="button" class="step-1 coda-nav-right"&gt;Find Courses Now&lt;/button&gt;'),
    $button4 = $('&lt;button type="button" class="step-2"&gt;Next&lt;/button&gt;'),
    $field1  = $('#webform-client-form-2 #webform-component-section-1'),
    $field2  = $('#webform-client-form-2 #webform-component-section-2'),
    $field3  = $('#webform-client-form-2 #webform-component-section-3'),
    $field4  = $('#webform-client-form-2-1 #webform-component-section-1'),
    $field5  = $('#webform-client-form-2-1 #webform-component-section-2'),
    $field6  = $('#webform-client-form-2-1 #webform-component-section-3');

$field1.addClass('panel');
$field2.addClass('panel');
$field3.addClass('panel');

$field2.hide();
$field3.hide();
$field5.hide();
$field6.hide();

$button1.appendTo($field1);
$button3.appendTo($field4);

$button1.click(function(){
    var $this = $(this);
    $this.parent().hide();
    $('.policy').hide();
    $field2.show();
    $button2.appendTo($field2);


$button2.click(function(){
    var $this = $(this);    
    $this.parent().hide();
    $field3.show();
    $('#edit-actions').show();
    $field2.append($button2);    
});

$button3.click(function(){
    var $this = $(this);
    $this.parent().hide();
    $('.policy').hide();
    $field5.show();
    $button4.appendTo($field5);     
});

$button4.click(function(){
    var $this = $(this);   
    $this.parent().hide();
    $field6.show();
    $('#webform-client-form-2-1 #edit-actions').show();
    //$field6.append($button3);   
});

})(jQuery);
</code></pre>
