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!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.