Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<DOMElement::setAttributeNodeDOMElement::setAttributeNS>
^DOMElementLast updated: Mon, 26 Oct 2026

DOMElement::setAttributeNodeNS

(PHP 5, PHP 7, PHP 8)

DOMElement::setAttributeNodeNS — Adds new attribute node to element

Description

public function DOMElement::setAttributeNodeNS(DOMAttr $attr): DOMAttr|null|false

Adds new attribute node attr to element, keeping the namespace into account. If an attribute with the same name already exists on the element, that attribute is replaced by attr.

Parameters

attr

The attribute node.

Return Values

Returns the old attribute if it has been replaced or null if there was no old attribute. If a DOM_WRONG_DOCUMENT_ERR error is raised, and strictErrorChecking is false, false is returned.

Errors/Exceptions

May throw a DOMException with the following error codes:

DOM_WRONG_DOCUMENT_ERR

Raised if attr belongs to a different document than the element.

See Also


<DOMElement::setAttributeNodeDOMElement::setAttributeNS>
^DOMElementLast updated: Mon, 26 Oct 2026