Web Development with jQuery®

(Elliott) #1

Setting, Retrieving, and Removing Attributes (^) ❘ 95
var input = getCheckbox();
alert('Disabled: ' + input.attr('disabled'));
}
);
The third block of code removes the disabled attribute with the removeAttr() method.
$('button#documentRemoveAttribute').click(
function(event)
{
event.preventDefault();
var input = getCheckbox();
input
.removeAttr('disabled')
.parent('li')
.removeClass('disabled');
}
);
The removeAttr('disabled') method completely removes the disabled attribute from the DOM.
When working with boolean HTML attributes, jQuery also allows setting a boolean value using
the attr() method, so attr('disabled', false) is functionally the same as removeAttr('disabled').
After removing the disabled attribute, you have the result in Figure 4-3.


FIGURE 4-3


When you attempt to retrieve the value of the disabled attribute after using either


removeAttr('disabled') or attr('disabled', false), you get a result of undefined, as shown in


Figure 4-4.


http://www.it-ebooks.info

Free download pdf