Add remove element jquery OR add remove html jquery

Add /Remove dynamically HTML element with jQuery
First of all you must have to include jQuery library

jQuery Section

    //getting the current element count
    var current = $("#answercount").val();
    current = Number(++current);
    //Append the html content
      $("#choiceTemplate").append("<div class='inputsection' 
         id='current" + current + "'>Title " + current + ":
         <input id='title" + current + "' name='title[]' 
         size='20' type='text' /></div>");
      //assign the current element count

    return false;

  //remove the elements
    //getting the current/last element count
    var current = $("#answercount").val();

    //removing the element
    //assign the current element count
    current = Number(--current);





HTML section

<div id="choiceTemplate">
   <input id="answercount" name="answercount" value="0"

<div id="addremovelink" style="clear: both;">
   <a id="removechoice" href="javascript:;" style="display:none;">
   <a id="addchoice" href="javascript:;">Add</a>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s