Ignore first input reading

Asked

Viewed 56 times

2

How do I ignore reading the first value of an array? I don’t want to remove it, I just want it to be displayed, it doesn’t appear the same:

I’ve done it before:

document.querySelectorAll('.form .form-control').forEach(function (a) {
   console.log(a.value);
});
<form class="form">
    <input type="hidden" class="form-control" value="Não é pra aparecer">
    <input type="text" class="form-control" value="Teste1">
    <input type="text" class="form-control" value="Teste2">
    <input type="text" class="form-control" value="Teste3">
</form>

The first input as you can see, is just an input of type Hidden and I don’t want its value to appear, but I also don’t want it to be removed... Someone give me a light?

Thank you!

  • 1

    Is there a need to use the form-control class in this input? Because if you don’t use it, it won’t enter foreach

  • Puts, Nathan, KKKKKKKK is sometimes every stupid thing I do, thanks man!

  • 1

    In programming is normal.

  • If you want to put it as an answer, then I’ll mark how you accept!

  • Okay, I put a little bit better explained to whoever needs it.

2 answers

2

If you want to ignore the element because it is "Hidden", just do it on the selector, with :not([type="hidden"]).

Or if you want to ignore the first, switch to a command for ignoring the first element.

See below the two examples:

console.log("ignorando hidden");
document.querySelectorAll('.form .form-control:not([type="hidden"]').forEach(function (a) {
   console.log(a.value);
});


console.log("ignorando primeiro elemento");
var elementos = document.querySelectorAll('.form .form-control');
for(var x=1; x<elementos.length;x++) {
  console.log(elementos[x].value);
}
<form class="form">
    <input type="hidden" class="form-control" value="Não é pra aparecer">
    <input type="text" class="form-control" value="Teste1">
    <input type="text" class="form-control" value="Teste2">
    <input type="text" class="form-control" value="Teste3">
</form>

1


You can take the class form-control of <input type="hidden" class="form-control" value="Não é pra aparecer">, for thus, he will not be called by:

document.querySelectorAll('.form .form-control').forEach(function (a) {
   console.log(a.value);
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.