Text of developer.mozilla.org › en-US › docs › Web › API › ProcessingInstruction › getAttribute as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

ProcessingInstruction: getAttribute() method - Web APIs | MDN

Skip to main content Skip to search ProcessingInstruction: getAttribute() method Limited availability This feature is not Baseline because it does not work in some of the most widely-used browsers. Want more browser support for this feature? Tell us why. See full compatibility Learn more Experimental: This is an experimental technology Check the Browser compatibility table carefully before using this in production. 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="&lt;b&gt;hi&lt;/b&gt;"', ); 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 Browser compatibility See also ProcessingInstruction.hasAttribute() ProcessingInstruction.hasAttributes() ProcessingInstruction.getAttributeNames() ProcessingInstruction.setAttribute() ProcessingInstruction.removeAttribute() ProcessingInstruction.toggleAttribute() Help improve MDN Learn how to contribute This page was last modified on Aug 27, 2026 by MDN contributors .

View this page on GitHub • Report a problem with this content