I want to add text boxes on button click using jquery in lightning component. On a button click i am unable to maintain a counter value in helper file. Where can i maintain counter value. How can i achieve the same. Here is my code.
Controller.js
addOption: function(component, event, helper) {
helper.addOption();
}
Helper.js
addOption: function(component, event, helper){
alert("Add option button clicked");
if(counter>4)
{
alert("Only 4 options allowed");
return false;
}
//Iterate number of option and create option textbox.
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'OptionDiv' + counter);
newTextBoxDiv.after().html('<label>Option #'+ counter + ' : </label>' +
'<input type="text" name="option' + counter +
'" id="option' + counter + '" value="" >');
newTextBoxDiv.appendTo("#OptionGroup");
counter++;
}
counter
variable?