What is the simplest way to hide labels and inputs with javascript?
I would use a combination of CSS and JavaScript for this use-case. Essentially what you want to achieve is a simple solution to showing and hiding form elements.

This is what I would suggest for markup:

&lt;form id="myform" method="POST" action="/some/processing/script"&gt;
    &lt;fieldset id="group-a" class="input-group"&gt;
        &lt;label for="my-input-element-1" class="input-wrapper"&gt;
            &lt;span&gt;My Element Label&lt;/span&gt;
            &lt;input type="text" id="my-input-element-1" value="" /&gt;
        &lt;/label&gt;

        &lt;!-- Repeat as many times as you need --&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;


CSS:

#myform label {
    display: block;
    margin: 0 0 10px 0; /* Set the bottom margin to whatever you want */
}

#myform label &gt; span {
    display: block;    /* display:block will force the input element below it */
    margin: 0 0 3px 0; /* Set the bottom margin to whatever you want */
}

#myform label &gt; input[type="text"] {
    display: block;    /* The default is inline, but we want to span the whole width */
    width: 100%; /* Full width */
    padding: 5px 0; /* Trick to allow an input to span the full width, without poking out of the containing element */
    margin: 0; /* Set the bottom margin to whatever you want */
    text-indent: 5px; /* Indent the text to make it appear normally */
}

#myform label.hidden {
    display: none !important;
    visibility: hidden !important;
}

/* OR */

.hidden {
  display: none !important;
  visibility: hidden !important; /* Prevent element from affecting the box model, e.g. whitespace between visible, surrounding elements  */
}


Now, with this setup in mind, you should only have to add or remove the class .hidden from either the containing &lt;label /&gt; element or apply it to the &lt;fieldset /&gt; element if you want to hide the whole group.

Also, if you're going to go to the trouble of hiding input fields, I'd recommend setting the disabled attribute, e.g. &lt;input type="text" disabled="disabled" /&gt; to prevent it's values from being serialized/submitted as part of the form.