$attr.get
Get the value of an attribute from element.
$attr.get( element, name )
element [object]
The target element.name [string]
The attribute name.
Notes
The replacement of getAttribute().
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