Documentación offline PHP master

DOMElement::setAttributeNode

master Ver versión oficial en línea Licencia CC-BY-3.0Descargado el 2026-08-02

En esta página

DOMElement::setAttributeNode

Añade un nuevo atributo al elemento

Descripción#

php public DOMElement::setAttributeNode(DOMAttr $attr): DOMAttrphp

Añade un nuevo atributo attr al elemento. Si ya existe un atributo con el mismo nombre en el elemento, este atributo es reemplazado por attr.

Parámetros#

attr
El atributo.

Valores devueltos#

Devuelve el atributo antiguo si ha sido reemplazado o null si no había un atributo antiguo. Si se produce un error DOM_WRONG_DOCUMENT_ERR y strictErrorChecking es false, entonces false es devuelto.

Errores/Excepciones#

Puede lanzar una DOMException con los siguientes códigos de error:

DOM_WRONG_DOCUMENT_ERR
Lanzado si attr pertenece a un documento diferente al del elemento.

Véase también#

DOMElement::hasAttribute, DOMElement::getAttributeNode, DOMElement::removeAttributeNode