Remove from input fields that are in hidden divs

I have one form and a pair of divs with a bunch of input fields and one select box that shows one div and hides all the others. This input field has the html5 required tag. I would like to remove the required tag from all input fields that are in hidden divs. How can i do this? Here is my js for showing / hiding divs depending on my selection options:

    <script>
function changeGroup(e) {
    /*
        1 - Remove all group classes
        2 - Add the currently selected group class
    */
    $("#main")
        .removeClass(allGroups)
        .addClass($("option:selected", e.target).val())     
}

/* 
    1 - Bind changeGroup function to "change" event
    2 - Fetch all group from the select field 
*/
var allGroups = $("select")
    .change(changeGroup)
    .find("option")
        .map(function() {
            return $(this).val();
        })
        .get()
        .join(' ');


</script>

Thanks for the help ... Dorijan

+4
source share
2 answers

prop(), required . , , , , .

required , required.

$('.required').prop('required', function(){
   return  $(this).is(':visible');
});

required

+4

"" div jQuery, :

$("#hiddenDiv :input").prop('required',null);
+2

All Articles