ProcessingInstruction: getAttribute() method
The getAttribute() method of the
ProcessingInstruction interface returns the value of a specified attribute on the
processing instruction.
If the given attribute does not exist, the value returned will be null.
Syntax
js
getAttribute(attributeName)
Parameters
attributeName-
The name of the attribute whose value you want to get.
Return value
A string containing the value of attributeName if the attribute exists; otherwise null.
Description
>Casing
Processing instruction arguments are case-sensitive.
Decoded character references in attribute values
HTML character references in an attribute's source markup (for example, <, &, or <) are decoded by the HTML parser when the document is parsed, so getAttribute() returns the decoded value, not the source.
For example:
js
const pi = document.createProcessingInstruction(
"start",
'data-payload="<b>hi</b>"',
);
pi.getAttribute("data-payload");
// <b>hi</b>
Examples
>Basic usage
js
const pi = document.createProcessingInstruction("start", 'name="placeholder"');
console.log(pi.getAttribute("name"));
// Logs:
// "placeholder"
Specifications
| Specification |
|---|
| DOM> # dom-processinginstruction-getattribute> |