Search code examples
jquerycontainscase-insensitive

JQuery: Make contains case insensitive


I have looked at other solutions to this on this site, but can't see how to adapt for my situation. I have the following code which looks for a label containing 'Size', but it needs to find 'size' too.

    <script type="text/javascript">
        $(document).ready(function() {                                                       

            if ( $('.productOptionsBlock label:contains("Size")').length > 0 ) {
                $('.productOptionsBlock label:contains("Size")').replaceWith('<label>Please select your size:</label>');
            }

        });
    </script>       

As a JQuery newby, I can't see how to apply the other functions I've found...

Many thanks,

Andy


Solution

  • $.expr[':'].Contains = function(x, y, z){
        return jQuery(x).text().toUpperCase().indexOf(z[3].toUpperCase())>=0;
    };