Add sequential ID to DIV and then hide

Asked

Viewed 35 times

-3

I have to manipulate some fields without having access to form.

When I am hiding the input fields, you are setting the lines of the div, causing form stay with holes between the lines.

My idea would be to add sequential id to these divs to then hide.

If you have any other suggestions, you are most welcome.

inserir a descrição da imagem aqui

Today I’m applying setAttribute and style all through the window.onload:

window.onload = function(){
      document.getElementById('rd-text_field-kkzqscvf').onblur = function(){validarCPF(this);}
      document.getElementById('rd-text_field-kkzqscvj').setAttribute("maxlength", "10");
      document.getElementById('rd-number_field-kkzqscvp').style.visibility = "hidden"
etc...
   }

1 answer

-2

As far as I can understand, you intend to hide the Divs that parent input elements and would like when an input is hidden the div is also.

Based on this assumption, consider putting id on Ivs instead of input itself, even though through the div you can access the input by being the same, child of the div.

You can also do the reverse by taking the parent input that has the id. Consider seeing this issue that is in the stack overflow: how to catch a Parent element from a child with id?

From this I believe that can be solved your problem. I hope to have helped! D

  • Hey, Matheus, thanks for the feedback. Actually I need to put ID in the DIV, because the form has several DIV all with the same class but none of them has ID. I’m checking how to resolve with this your suggestion in the stack overflow.

  • I managed to do it through your tip. I now need to adapt to call this Function the moment I load the form. Document.getElementById('Rd-number_field-kkzh10aq'). onkeypress = Function(){this.parentElement.style.display = 'None';};

  • I believe that in a vanilla javascript file can load a function in the creation of DOM you could do as follows: myFunction()


document.getElementById('rd-number_field-kkzh10aq').onkeypress = myFunction()


myFunction() {this.parentElement.style.display = 'none';}

  • I got this: var item = Document.getElementById("Rd-number_field-kkzh10aq"); Function removeLi() { item.parentNode.removeChild(item); ;}

  • [ Solved ] Added .parentElement.style.display = 'None'; Document.getElementById('id').parentElement.style.display = 'None;';

Browser other questions tagged

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