jquery addclass not working on textarea

I'm using the following code to highlight any field that changes on multiple forms in on a page.
$(document).ready(function(){
     var jInput = $( ":input" );
          jInput.change(function( objEvent ){
               $( this ).addClass( "dirty" );
           }
     );      
});

<style type="text/css">
   input.dirty {
        border:1px solid #660000;
        outline: 1px solid #660000;        
    }
</style>

It works perfect for all the input types: text, select, checkbox, radio. It does not work for textarea though.

When I look at it in firebug, it shows that the class is added in the HTML code but it doesn't apply in the css like it does for the other input types.
LVL 2
chemdryAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
textarea is not input
0
hieloCommented:
that's because your css is specifically targetting <INPUT> elements :
  input.dirty{...}


get rid of input:
.dirty{...}

OR add the textarea element
input.dirty, textarea.dirty{..}


do not confuse jQuery selectors with CSS selectors. Two completely different worlds.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chemdryAuthor Commented:
For jquery it is if i'm reading it right. Plus i am seeing the class added to the code, just not applied.
If not how would i accomplish this?

http://api.jquery.com/input-selector/
0
chemdryAuthor Commented:
Perfect Hielo, I was looking at in the wrong area for the answer. Changed input.dirty to .dirty and that did it durh
0
hieloCommented:

you used the selector correctly. AND like you stated:
"When I look at it in firebug, it shows that the class is added in the HTML code.."

So jquery is also working fine, BUT the browser does not acknowledge the css rules because YOUR css rules explicitly say:

apply these:
        border:1px solid #660000;
        outline: 1px solid #660000;        

ONLY to <INPUT> elements with class="dirty"

When jquery sees ":input" it includes <INPUT> AND <TEXTAREA> elements, BUT for CSS, <INPUT> and <TEXTAREA> elements are different elements!

apply the changes from my previous post

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.