0

Ahora mismo intento seleccionar todos los input que contiene el documento menos uno, que está en hidden, y no quiero que se vea en ningún sitio (PD: Es el último input seleccionado siempre).

Tengo este código:

const inputs = document.querySelectorAll('input');

Y el input que necesito eliminar de la selección se forma dinámicamente así:

for (let i in params){
         var hi0     =   document.createElement('input');
         hi0.type    =   'hidden'; //cambiar a text si hay que verlo
         hi0.name    =   i;
         hi0.value   =   params[i];
         this.div0.querySelector('form').appendChild(hi0);
      }

¿Cómo podría hacer para eliminar ese input de la selección?

1 respuesta 1

2

Puedes utilizar el selector :not para excluir los que no te interesan y a este le puedes añadir una regla de tipo ; 'input:not([type="hidden"])'

<!DOCTYPE html>
<html>
<head>
<title>Seleccionar todos los input menos uno</title>
</head>
<body>
<div>
    <form></form>
</div>

</body>
</html>
<script>
    var Hiddenparams=["Param1","Param2","Param3","Param4"];    
    var NotHidden=["N1","N2","N3","N4"];
    document.addEventListener("DOMContentLoaded", function(event) { 
        for (let i in Hiddenparams){
            var hi0     =   document.createElement('input');
            hi0.type    =   'hidden'; //cambiar a text si hay que verlo
            hi0.name    =   i;
            hi0.value   =   Hiddenparams[i];
            document.querySelector('form').appendChild(hi0);
        }
        for (let i in NotHidden){
            var hi0     =   document.createElement('input');
            hi0.type    =   'text'; //cambiar a text si hay que verlo
            hi0.name    =   i;
            hi0.value   =   NotHidden[i];
            document.querySelector('form').appendChild(hi0);
        }

        const inputs = document.querySelectorAll('input:not([type="hidden"])');
        console.log("Inputs: ",inputs);

    });
    
</script>

1
  • 1
    Que bueno, ni lo conocía ni me sonaba. Muchisimas gracias
    – AQMR
    el 15 mar. 2021 a las 8:27

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.