Returns the value of the given attribute on the given element, cast as a boolean value.
If the attribute value cannot be cast to true
or false
, undefined
is returned.
This function deviates from the
HTML Standard for boolean attributes
in order to allow undefined
values. When an attribute is missing, Unpoly considers the value to be undefined
(where the standard would assume false
).
Unpoly also allows "true"
and "false"
as attribute values.
The table below shows return values for up.element.booleanAttr(element, 'foo')
given different elements:
Element | Return value |
---|---|
<div foo> |
true |
<div foo="foo"> |
true |
<div foo="true"> |
true |
<div foo=""> |
true |
<div foo="false"> |
false |
<div> |
undefined |
<div foo="bar"> |
true |
The element from which to retrieve the attribute value.
The attribute name.
The cast attribute value.