How can I add an attribute into specific HTML tags in jQuery?
For example, like this simple HTML:
<input id="someid" />
Then adding an attribute disabled="true" like this:
<input id="someid" disabled="true" />
You can add attributes using attr
like so:
$('#someid').attr('name', 'value');
However, for DOM properties like checked
, disabled
and readonly
, the proper way to do this (as of JQuery 1.6) is to use prop
.
$('#someid').prop('disabled', true);