Posts Tagged ‘add remove’

Dynamically Add Remove Elements using jQuery

Dynamically Add Remove Elements using jQuery

Sample code snippet for Adding and Removing the Elements dynamically using jQuery
{code type=html}

Answer Choice 1 :

{/code}

Javascript

{code type=html}
$(document).ready(function() {

$(“#addchoice”).click(function(){
//getting the current element count
var current = $(“#answercount”).val();
current = Number(++current);

//Append the html content
$(“#choiceTemplate”).append(”

Answer Choice ” + current + ” :

“);

//assign the current element count
$(“#answercount”).val(current);

return false;

});

//remove the elements
$(“#removechoice”).click(function(){

//getting the current/last element count
var current = $(“#answercount”).val();

//removing the element
$(‘#current’+current).remove();

//assign the current element count
current = Number(–current);
$(“#answercount”).val(current);
});

});

{/code}

Submitted By : Raja

Demo 

Subscribe to RSS Feed Follow Ajaxmint on Twitter!
Get Adobe Flash playerPlugin by wpburn.com wordpress themes