jQuery Each not working in IE9

I have the following code to add some validation to a form within an on click function.

    $(this).parent().find('input[type=text]:required').each(function() {
        alert('each');
        if($(this).val() == '') {
            $(this).css('border-color', '#df8f8f');
            required_missing = true;
        } else {
            $(this).css('border-color', '#eeece4');
        }
    });

An alert above this code works, but the alert within it does not appear in IE9. I have a sneaky suspicion that it may be the :required pseudo selector, is there an alternative for IE?

Answers


Try this instead:

$(this).parent().find('input[type=text][required]').each(function() {

or:

$(this).parent().find('input[type=text]').each(function() {
    if($(this).attr('required')) {
        alert('each');
        if($(this).val() == '') {
            $(this).css('border-color', '#df8f8f');
            required_missing = true;
        } else {
            $(this).css('border-color', '#eeece4');
        }
    }    
});

IE9 doesn't support the required attribute. Suggest you do a check for < IE9 and replace with a css class check instead.


Need Your Help

Can't call animated png script from external js file

jquery scripting png external animated

I'm trying to put an animated PNG dynamically from external .js file. First I found a simple animated png solution, which draws an animation wherever you put the code within &lt;script&gt; tags, ...