MDN self-hosted library · e01.org

ProcessingInstruction: hasAttribute() method

DOM

DOM

The hasAttribute() method of the ProcessingInstruction interface returns a boolean value indicating whether the specified element has the specified attribute or not.

Syntax

hasAttribute(name)

Parameters

  • name
  • : A string representing the name of the attribute.

Return value

A boolean.

Examples

Basic usage

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

console.log(pi.hasAttribute("name"));
// logs:
// true

Specifications

Browser compatibility

See also

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