How can I clone this block and also increment the title number and if possible increment the ids?
To each div "block-1" i want to have add and delete option. Thanks in advance
<div class="block-1">
<div class="fieldset-emp">
<fieldset>
<h4>title 1</h4>
<label class="field-first arrow">First Name<em class="required">*</em><input type="text" name="first_name" id="first_name" value="" /></label>
<label class="field-last arrow">Last Name<em class="required">*</em><input type="text" name="last_name" id="last_name" value="" /></label>
<label class="field-mi arrow">Middle Initial<em class="required">*</em><input type="text" name="mi" id="mi" value="" /></label>
<label class="field-ssn arrow">Social Security #<em class="required">*</em><input type="text" name="ssn" id="ssn" value="" /></label>
<div class="eesradioitem-1">
<label class="field-faddress arrow">Foreign Address<em class="required">*</em></label>
<div class="eesradioitem">
<label>Yes </label>
<input type="radio" name="faddress" value="yes" />
</div>
<div class="eesradioitem">
<label>No</label>
<input type="radio" name="faddress" value="no" checked="checked"/>
</div>
</div>
<label class="field-address1 arrow">Address line 1<em class="required">*</em><input type="text" name="address1" id="address1" value="" /></label>
<label class="field-address2 arrow">Address line 2<em class="required">*</em><input type="text" name="address2" id="address2" value="" /></label>
<label class="field-city arrow">City <em class="required">*</em><input type="text" name="city" id="city" value="" /></label>
<label class="field-email arrow">Email <em class="required">*</em><input type="text" name="email" id="email" value="" /></label>
<label class="field-dob arrow">Date of Birth <em class="required">*</em><input type="text" name="dob" id="dob" value="" /></label>
<label class="field-homephone arrow">Home Phone<em class="required">*</em><input type="text" name="homephone" id="homephone" value="" /></label>
<label class="field-gender arrow">Gender <em class="required">*</em><input type="text" name="gender" id="gender" value="" /></label>
</fieldset>
</div>
</div>
If you're using the jQuery javascript Framework, you can do something like this...
Build a function...
...which will enable you to do something like this, where
#id_of_your_block_container
is a selector for the element that will contain all of your blocks...Just as a side note it would be better practice to have all of your "block"
<div>
s have aclass
of"block"
and have uniqueid
s, e.g.I added a couple of buttons to your markup in my example here: http://jsfiddle.net/w4efg/ then it is just:
Note the classes in my CSS just to show it working on the first three.
My example is a bit verbose to show what it does clearly if you want to chunk it down a bit. It also allows the first block to be deleted which might be bad :). And the logic for the index just adds a new number, so the block-xx gets the xx as the index AFTER the block you click in and might be better done.
EDIT: I added the "title" stuff (might want a class on the h4 for title) and took out some code as noted in this update: http://jsfiddle.net/w4efg/1/