$('label[id="p-n-from"]').on('click',function() {
var fromele = $('<div id="p-n-from-'+ifrom+'" class="input-control text" data-role="input"><span class="mif-location prepend-icon"></span><input id="from['+ifrom+']" placeholder =" Enter Pick Up Location" type="text" required></div>');
$(fromDiv).append(fromele);
return false;
});
<div class="col-md-6 ">
<label class="input-control ">From</label>
<div id="from-div">
<div id="p-n-from-1" class="input-control text" data-role="input">
<span class="mif-location prepend-icon"></span>
<input id="from[0]" placeholder="Enter pickup " type="text" required>
</div>
</div>
<div id="" class="col-md-6 ">
<label id="p-n-from" class="input-control">
<button class="button mini-button cycle-button mif-plus fg-green"></button>Add More</label>
</div>
</div>
<div class="col-md-6 ">
<div id="to-div">
<label class="input-control ">To</label>
<div id="p-n-to-1" class="input-control text" data-role="input">
<span class="mif-location prepend-icon"></span>
<input id="to[0]" placeholder="Enter drop location" type="text" required>
</div>
</div>
</div>
This is simple script is adding the input box twice, although the most of the form has dynamically added elements.
I can't figure out why this one is getting added twice. I have tried suggestions from this Appending a DOM element twice (jQuery)
But it didn't help. How can I resolve this issue?