DiDom\Element::setAttribute PHP Method

setAttribute() public method

Set an attribute on the element.
public setAttribute ( string $name, string $value ) : Element
$name string The attribute name
$value string The attribute value
return Element
    public function setAttribute($name, $value)
    {
        if (is_numeric($value)) {
            $value = (string) $value;
        }
        if (!is_string($value) and $value !== null) {
            throw new InvalidArgumentException(sprintf('%s expects parameter 2 to be string or null, %s given', __METHOD__, is_object($value) ? get_class($value) : gettype($value)));
        }
        $this->node->setAttribute($name, $value);
        return $this;
    }

Usage Example

示例#1
0
 public function testSetAttribute()
 {
     $domElement = $this->createDomElement('input');
     $element = new Element($domElement);
     $element->setAttribute("value", "test");
     $domElement = $element->getElement();
     $this->assertEquals("test", $domElement->getAttribute("value"));
 }
All Usage Examples Of DiDom\Element::setAttribute