There are no tracking or monitoring cookies on this site. There are only cookies used for documentation examples related to cookies.

This may take a few seconds.



set-attribute: (attribute) (boolean|"string") [html-entity-decode] [every (time)] [after (time)][, (attribute)...];

This command adds a new attribute into the target selector if it doesn't exist, or replaces an attribute if it is already there.

The attribute parameter is the name of the attribute you want to use.

The boolean parameter accepts "true" or "false", if your attribute is either true or false. You can leave out the double-quotes for a boolean.

Or alternatively, the string parameter is what you want to have inside the attribute. It requires double-quotes - these are not optional.

The optional html-entity-decode parameter will convert an html escaped string (eg. like "&lt;div&gt;")  into valid html (eg. "<div>") before inserting into an attribute. Internally, the JavaScript setAttribute command is used, so the result of adding straight HTML into an attribute does not break the DOM, even if the value looks like unescaped HTML.


Properties and attributes can sometimes be a bit confusing. But the confusion lies in the terms themselves rather than the behaviour, as they are not particularly descriptive terms. Simply put, you can think of properties as being changeable (like .value, .disabled, .draggable) and the attributes are what are actually in the html tag itself.

For some of the difference between properties and attributes and recommended use, see this page: