1

Hi I am trying to select only the fields who's CSS property is not Display: "None". Please have a look at the code and please let me know what an I doing wrong?

function (controlId) { var returnValidFlag = true;

        //var requiredClass = $this.find('.required');
        //console.log(requiredClass);

        $('.required:not([display=none])').each(function () {
            // Get 'this' HTML object's ID
            var thisInputID = $(this).attr('id');

            // Get 'this' error message 
            var thisErrorMessageID = thisInputID + 'ErrorMessage';
            // console.log('Error ID: ' + thisErrorMessageID);

            // Get the user input value
            var thisInputValue = $(this).val();
            console.log('Input ID: ' + thisInputValue + " " + thisErrorMessageID);

            if (thisInputValue =='') {
                returnValidFlag = false;
                $('#' + thisErrorMessageID).show();
            } else {
                returnValidFlag = true;
                $('#' + thisErrorMessageID).hide();
            }
        });

        return returnValidFlag;
    }
1

2 Answers 2

1

You can use :visible selector.

display is not part of an element's attributes , it is a style property

$('.required:visible)').each(...
Sign up to request clarification or add additional context in comments.

Comments

0

In jQuery, you can use filter.

$('div').filter((index, node) => $(node).css('display') !== 'none')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.