Please take a look at the code below. This function is used to add more text input when user click con a button. I don't understand 2 things.
Why we need this?
var i = $('#p_scents p').size() + 1;
I don't understand what it is used for. I tested and see that the function still works as long as you definevar i
. I'm not sure if$('#p_scents p').size() + 1;
is necessary here.Why
return false;
in both 2 functions?
http://jsfiddle.net/jaredwilli/tzpg4/4/
$(function() {
var scntDiv = $('#p_scents');
var i = $('#p_scents p').size() + 1;
$('#addScnt').live('click', function() {
$('<p><label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt_' + i +'" value="" placeholder="Input Value" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').live('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});