views:

17

answers:

1

This should be really simple but I can't get it to work, how do I disable and add a class to an input? Let's say I've got an input field with id = name, this is how far I got,

$("input#name").attr("disabled");

What am I doing wrong here? Any help would be greatly appreciated, thanks in advance!

+2  A: 

You need to give .attr() a second parameter (the value to set, otherwise it gets the value), true in this case ("disabled" works too, but a boolean is desirable for a few reasons here):

$("input#name").attr("disabled", true).addClass('myClass');

.addClass() then adds that class to the element.

Nick Craver