Adding attribute in jQuery

html, jquery, tags

Solution

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);

Problem

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" /> ```

Original source

Related problems