1
I have a list that incremented dynamically with the jquery append, the list goes like this:
$("#questoes").append(
'<li class="questao" data-id="'+questao+'">'+
'<div class="row testes">'+
'<div class="left-col col col-md-11">'+
'<input type="number" class="form-input questao_numero" style="max-width: 160px" placeholder="Nº da questão" data-chave="numero_questao">' +
'</div>'+
'<div class="right-col col-6 col-md-1">'+
'<i data-toggle="collapse" data-parent="#accordion" href="#collapse-'+questao+'" aria-expanded="true" aria-controls="collapse-'+questao+'" class="questoes_arrow fa fa-caret-up" aria-hidden="true"></i></a>' +
'</div>'+
'</div>'+
'<div id="collapse-'+questao+'" class="collapse questoes_arrow_container show" role="tabpanel" aria-labelledby="heading-'+questao+'">' +
'<div class="questao-body">' +
'<h4 class="h5">Enunciado da questão: </h4>' +
'<textarea name="enunciado" class="form-control questao_enunciado" data-chave="questao_enunciado">Enunciado da questão</textarea>' +
'<div class="line"></div>' +
'<h4 class="h5">Alternativas da questão: </h4>' +
'<ul class="alternativas"></ul>'+
'<button type="button" class="btn btn-secondary btn-sm nova_alternativa">+ Add nova alternativa</button>' +
'<div class="line"></div>' +
'</div>' +
'</li>'
);
I am using the following code to go through the list elements and take the value of the inputs contained in each list item and put into an array:
$("#salvar_alteracoes").click(function(){
var questoes = new Array();
$("#questoes").each(function(i, e){
$(this).find('li').each(function (j) {
var questao = {
"questao_numero" : $(this).find('.questao_numero').val(),
"questao_enunciado" : $(this).find('.questao_enunciado').val(),
};
questoes.push(questao);
});
});
});
But using "$(this). find('.questao_numero'). val()" is not taking the input value because?
why is
<ul class="questoes">
to make it work<ul class="questoes" id="questoes">
– NoobSaibot
@Wéllingthonm.Souza In the original code is with id, is that when passing here I ended up putting wrong. And it doesn’t work anyway
– Leandro Silva Campos