Confirmed users
1,396
edits
Line 159: | Line 159: | ||
<code> | <code> | ||
AttributeSet .''hasAnyOf'' | AttributeSet .''hasAnyOf'' | ||
::Return true if any of the | ::Return true if any of the object properties matches to the object attributes. | ||
AttributeSet .''hasAllOf'' | AttributeSet .''hasAllOf'' | ||
::Return true if all | ::Return true if all of the object properties matches to the object attributes. | ||
</code> | </code> | ||
Each property of the object is a string or an array of strings. If array of strings is given then the object attribute is expected to have any of given values, empty array means the attribute value doesn't matter for match. String value and null values are treated as single element array or empty array correspondingly. | |||
Example | <b>Example #1.</b> | ||
<pre> | <pre> | ||
var | var attrs = { | ||
var autocomplete = | live: [ "assertive", "polite" ], | ||
relevant: "show", | |||
busy: null | |||
}; | |||
var matched = accEl.hasAllOf(attrs); | |||
// Matches if the ccessible element has "live" object attribute of | |||
// "assertive" or "polite" values, has "relevant" object attribute of | |||
// "show" value, and it has "busy" attribute. | |||
</pre> | |||
<b>Example #2. Process autocomplete.</b> | |||
<pre> | |||
var accEl = document.getElementById("foo").a11ement; | |||
var checkObj = { autocomplete: [ "list", "both" ] }; | |||
if (accEl.attributes.hasAllOf(checkObj)) { | |||
doAutocomplete(); | |||
} | |||
// Alternatively you can do | |||
var autocomplete = accEl.attributes.get("autocomplete"); | |||
if (["list", "both"].indexOf(autocomplete) != -1) { | if (["list", "both"].indexOf(autocomplete) != -1) { | ||
doAutocomplete(); | |||
} | } | ||
</pre> | </pre> |