JQuery iterating through textboxes and changing its color

Posted by bill-nielsen on Stack Overflow See other posts from Stack Overflow or by bill-nielsen
Published on 2010-03-18T18:03:52Z Indexed on 2010/03/18 18:11 UTC
Read the original article Hit count: 353

Filed under:

I'm trying to iterate through all the empty textboxes in a table and change its background colour. I'm using the following JQuery code:

    $("#btn2").click(function() {
            var emptyTextBoxes = $('input:text').filter(function() { return this.value == ""; });
            emptyTextBoxes.each(function() {
            this.css('background-color', '#ffff00');
//            $('#Col3Txtbx').css('background-color', '#ffff00');    
            });
        });

This does not seem to refer to the textbox which seems strange to me. When I uncomment out the particular textbox, it does reset the background colour.

Can someone explain to me what 'This' is referring to?

© Stack Overflow or respective owner

Related posts about jQuery