Alex Rivera | Logout

addAttr not working in jquery?

Asked 2012-05-02T04:15:23.550
29

I have a sample code :

<input type="text" name="color" id="color" value="" />

And jquery

$('#color').change(function(){
    $('#color').addAttr('value', 'test');
});

When I change value in textbox is result value="" and error in firebug $("#color").addAttr is not a function

How to fix it ?

Edit
Report

1 Answer

19

You are confused about removeAttr() and you think that addAttr() exists, that's wrong.

The function you want is .attr() - nowadays .prop(), I believe.

answered 2012-05-02T04:21:50.587

Your Answer