Edit this page

up.element up.element.booleanAttr(element, attribute)
JavaScript function

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.

Casting rules

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

Parameters

element
required

The element from which to retrieve the attribute value.

attribute
required

The attribute name.

string

Return value

The cast attribute value.

booleanundefined