DiDom\Element::getAttribute PHP Method

getAttribute() public method

Access to the element's attributes.
public getAttribute ( string $name, string $default = null ) : string | null
$name string The attribute name
$default string The value returned if the attribute does not exist
return string | null The value of the attribute or null if attribute does not exist
    public function getAttribute($name, $default = null)
    {
        if ($this->hasAttribute($name)) {
            return $this->node->getAttribute($name);
        }
        return $default;
    }

Usage Example

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