大网数据广告活动
Web 标准与前端开发

ProcessingInstruction: getAttributeNames() method

· 52CE 我爱测

The **`getAttributeNames()`** method of the ProcessingInstruction interface returns the attribute names of the processing instruction as an Array of strings. If the processing instruction has no attributes it returns an empty array.

DOM

The getAttributeNames() method of the ProcessingInstruction interface returns the attribute names of the processing instruction as an Array of strings. If the processing instruction has no attributes it returns an empty array.

Syntax

getAttributeNames()

Parameters

None.

Return value

An Array of strings.

Description

Using getAttributeNames() along with ProcessingInstruction.getAttribute is a memory-efficient and performant alternative to accessing ProcessingInstruction.data.

The names returned by getAttributeNames() are qualified attribute names, meaning that attributes with a namespace prefix have their names returned with that namespace prefix (not the actual namespace), followed by a colon, followed by the attribute name (for example, xlink:href). Any attributes without a namespace prefix have their names returned as-is (for example, href).

Examples

Basic usage

const pi = document.createProcessingInstruction(
  "start",
  'name="placeholder" more="info"',
);

console.log(pi.getAttributeNames());
// logs:
// ['name', 'more']

// Iterate over processing instruction's attributes
for (const name of pi.getAttributeNames()) {
  const value = pi.getAttribute(name);
  console.log(name, value);
}
// logs:
// name placeholder
// more info

Specifications

Browser compatibility

See also

  • ProcessingInstruction.hasAttribute()
  • ProcessingInstruction.hasAttributes()
  • ProcessingInstruction.getAttribute()
  • ProcessingInstruction.setAttribute()
  • ProcessingInstruction.removeAttribute()
  • ProcessingInstruction.toggleAttribute()

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。