$dom = new DOMDocument(); $element = $dom->createElement('div'); $element->setAttribute('class', 'my-class');
$dom = new DOMDocument(); $element = $dom->createElement('div'); $element->setAttribute('class', 'old-class'); // Change the class to "new-class" $element->setAttribute('class', 'new-class');
$dom = new DOMDocument(); $element = $dom->createElement('div'); $element->setAttribute('class', 'my-class'); // Add a "data-name" attribute with the value "John" $element->setAttribute('data-name', 'John');This code creates a new div element with the class attribute "my-class" and then adds a new attribute called "data-name" with the value "John". The package library for PHP DOMNode is included with the core PHP language.