1
$("#divOpcoes").fadeOut(500, function () { $(this).text('Opção ' + indiceAtual + ".").fadeIn(500); })
The line above is within a for loop and "indiceAtual" variable is incremented with each loop pass. My problem is: the Function passed to fadeOut is only executed after the whole loop ends, and my result is: for all of the indiceAtual passed passed passes the value of the last passed loop, but the expected result is that each passed by the loop the value is that of indiceAtual at that time.
EDIT1
A little more of my code:
Working without the animation:
if (nextLabel != null) {
$("#divOpcoes").find("#lbOpcao" + (indiceAtual + 1)).text('Opção ' + indiceAtual + ".").attr('for', 'Opcao' + indiceAtual).attr('id', 'lbOpcao' + indiceAtual);
$("#divOpcoes").find("#divOpcao" + (indiceAtual + 1)).attr('id', 'divOpcao' + indiceAtual);
$("#divOpcoes").find("#Opcao" + (indiceAtual + 1)).attr('id', 'Opcao' + indiceAtual);
$("#divOpcoes").find("#btn" + (indiceAtual + 1)).prop('onclick', null).off('click').attr('onclick', "excluirOpcao(" + indiceAtual + ")" ).attr('id', 'btn' + indiceAtual);
}
With animation, but putting all indices equal:
if (nextLabel != null) {
$("#divOpcoes").find("#lbOpcao" + (indiceAtual + 1)).fadeOut(500, function () { $(this).text('Opção ' + indiceAtual + ".").fadeIn(500); }).attr('for', 'Opcao' + indiceAtual).attr('id', 'lbOpcao' + indiceAtual);
$("#divOpcoes").find("#divOpcao" + (indiceAtual + 1)).attr('id', 'divOpcao' + indiceAtual);
$("#divOpcoes").find("#Opcao" + (indiceAtual + 1)).attr('id', 'Opcao' + indiceAtual);
$("#divOpcoes").find("#btn" + (indiceAtual + 1)).prop('onclick', null).off('click').attr('onclick', "excluirOpcao(" + indiceAtual + ")" ).attr('id', 'btn' + indiceAtual);
}
Applying setTimeout (did not work and returned error in the console):
if (nextLabel != null) {
setTimeout(function () {
$("#divOpcoes").find("#lbOpcao" + (indiceAtual + 1)).fadeOut(500, function () { $(this).text('Opção ' + indiceAtual + ".").fadeIn(500); }).attr('for', 'Opcao' + indiceAtual).attr('id', 'lbOpcao' + indiceAtual);
$("#divOpcoes").find("#divOpcao" + (indiceAtual + 1)).attr('id', 'divOpcao' + indiceAtual);
$("#divOpcoes").find("#Opcao" + (indiceAtual + 1)).attr('id', 'Opcao' + indiceAtual);
$("#divOpcoes").find("#btn" + (indiceAtual + 1)).prop('onclick', null).off('click').attr('onclick', "excluirOpcao(" + indiceAtual + ")").attr('id', 'btn' + indiceAtual);
}, 500+(i*1000));
}
EDIT2
my entire Function:
function reordenarOpcoes() {
for (i = 1; i <= $("#idOpcao").val() ; i++) {
var label = $("#divOpcoes").find("#lbOpcao" + i).val();
if (label == null) {
var nextLabel = $("#divOpcoes").find("#lbOpcao" + (i + 1)).val();
if (nextLabel != null) {
$("#divOpcoes").find("#lbOpcao" + (i + 1)).text('Opção ' + i + ".").attr('for', 'Opcao' + i).attr('id', 'lbOpcao' + i); // .fadeOut(500, function () { $(this).text('Opção ' + indiceAtual + ".").fadeIn(500); }).attr('for', 'Opcao' + indiceAtual).attr('id', 'lbOpcao' + indiceAtual);
$("#divOpcoes").find("#divOpcao" + (i + 1)).attr('id', 'divOpcao' + i);
$("#divOpcoes").find("#Opcao" + (i + 1)).attr('id', 'Opcao' + i);
$("#divOpcoes").find("#btn" + (i + 1)).prop('onclick', null).off('click').attr('onclick', "excluirOpcao(" + i + ")").attr('id', 'btn' + i);
}
}
}
}
Already tried using: $("#divOpcoes"). fadeOut(500). delay(500, Function () { $(this). text('Option ' + indiceAtual + "." ). fadein(500); })
– Wilson Faustino
Place the code in a way that includes the declaration of the
indiceAtual
and preferably also the tie, to give you a clearer idea of what you’re trying to do– Isac
@W.Faustino tried to use, but the result was that all texts were fadeOut and no fadein, rs.
– M. Bertolazo
@Isac indiceAtual is a var = 1, performed an Edit, will it suffice?
– M. Bertolazo