Search code examples
jqueryrequiredfieldvalidator

jQuery filter span by property value


I am attempting to only query the Page_Validators that have an isvalid property set to false. I tried using

$(Page_Validators).filter('span[isvalid=true]')

but it does not return any results. Strangely when I query a validator by id

$(Page_Validators).filter('span[id$=bob]')

it works. What is up with the isvalid property and why can I not query by it?

As requested here is the markup for one of the validators

<span class="detail-required-validator" id="ctl00_MainContent_Service_Name_Validator" style="visibility: visible;">*</span>

this totally makes sense now, there is no isvalid attribute in the markup. The Page_Validators object is an array of javascript representations of the above markup. so would I need $.grep?


Solution

  • Looks like the answer is to use $.grep because I am querying a javaScript array and not an array of span elements!

    var validators = $.grep(Page_Validators, function (n)
    {
        return n.isvalid == false;
    });
    

    The above code returns an array of asp.net RequiredFieldValidators that have controls with invalid inputs (if any)