I have an app where I can add input fields dynamically. however my buttons remain on their spot and I create 2 input fields underneath it.
What I would like to try and to achieve is: When I add the input fields I want the button to be underneath the input fields.
this is the function that creates the button.
function getAddBtn(target, i){
var addBtn = $('<a/>', {
'class': 'btn btn-primary',
'id': 'addBtn'
}).on('click', function(){
if($('.syllable',target).length>3)
return false;
$(target).append(getWordPartInput(i));
}).html('<i class="fa fa-plus"></i>');
console.log(target);
return addBtn;
}
and this is the function that creates the input fields:
function getWordPartInput(id, cValue){
cValue = cValue || '';
var wpInput = $('<input/>', {
'class': 'form-group form-control syllable',
'type': 'text',
'value': cValue,
'placeholder': 'Syllables',
'name': 'Syllablescounter['+ SyllablesID++ +']'
});
return wpInput;
}
https://jsfiddle.net/StackOverflowAccount/sa2eowhh/21/ a fiddle for you to try it urself and see what I mean. Click on the green add button, and then you see 2 buttons, a + button and a - button. Click the blue button and you can see how the input fields jump underneath the button instead of adding in between. I'm trying to keep the input fields underneath each other instead of having buttons in between.
thanks in advance.