I have a code that shows fields on the screen according to the click, after the first click it will increment a 'QtdClick' variable, it occurs that I did not want it to show all the fields, I only want when it is 2 second click, 3 click etc., individually.
Example:
<script>
$(document).ready(function(){
//esconde o campo na abertura da página
document.getElementById('extraum').style.display = 'none';
document.getElementById('extradois').style.display = 'none';
document.getElementById('extratres').style.display = 'none';
document.getElementById('extraquatro').style.display = 'none';
//se o botão for clikado 1 vez, mostra o campo
var QtdClick = 1; //inicindo
var btn1 = document.querySelector("#mostracampo1");
btn1.addEventListener('click',function(e){
if (QtdClick ==1 ){
document.querySelector("#extraum").style.display = 'block';
QtdClick++;
alert(QtdClick);
}
if (QtdClick ==2 ){
document.querySelector("#extradois").style.display = 'block';
QtdClick++;
alert(QtdClick);
}
if (QtdClick ==3 ){
document.querySelector("#extratres").style.display = 'block';
QtdClick++;
alert(QtdClick);
}
if (QtdClick ==4 ){
document.querySelector("#extraquatro").style.display = 'block';
QtdClick++;
alert(QtdClick);
}
});
});
</script>
html:
<input type="text" required class="form-control" id="extraum" placeholder="campo 1">
<input type="text" required class="form-control" id="extradois" placeholder="campo 2">
<input type="text" required class="form-control" id="extratres" placeholder="campo 3">
<input type="text" required class="form-control" id="extraquatro" placeholder="campo 4">
<a href="#" id="mostracampo1" class="btn btn-custom btn-branco btn-lg">Mostar Campo Botão</a>