Started

Selectors

Utilities

Animation

AJAX

CSS

Event

Manipulation

Cookie

String

Attributes

Data

Storage

Miscellaneous

$attr.set

Set the value of an attribute from element.
$attr.set( element, name, value )
  1. element [object]
    The target element.
  2. name [string]
    The attribute name.
  3. value [string]
    The value of attribute

Notes

The replacement of setAttribute().

Example

HTML code
<div id="box" title="this is the title of the box">This is a box</div>
<div id="message"></div>
<button onclick="start_attr_get()">Get box title</button>
<button onclick="start_attr_set()">Set box title</button>
<button onclick="start_attr_remove()">Remove box title</button>
CSS code
#box {
	width: 200px;
	height: 60px;
	font-size: 12px;
	background: #5599bb;
	padding: 10px;
}
JavaScript code
function start_attr_get()
{
	$html($("message"), "The title attribute of the box is:" + $attr.get( $("box"), "title"));
}

function start_attr_set()
{
	$attr.set($("box"), "title", "The title attribute has changed, hello!");
	$html($("message"), "Title changed");
}
function start_attr_remove()
{
	$attr.remove($("box"), "title");
}
Demonstration
This is a box