DiDom\Document::createElement PHP Method

createElement() public method

Create new element node.
public createElement ( string $name, string $value = null, array $attributes = [] ) : Element
$name string The tag name of the element
$value string The value of the element
$attributes array The attributes of the element
return Element created element
    public function createElement($name, $value = null, $attributes = [])
    {
        $node = $this->document->createElement($name);
        $element = new Element($node, $value, $attributes);
        return $element;
    }

Usage Example

Beispiel #1
0
 public function testCreateElement()
 {
     $html = $this->loadFixture('posts.html');
     $document = new Document($html, false);
     $element = $document->createElement('span', 'value');
     $this->assertInstanceOf('DiDom\\Element', $element);
     $this->assertEquals('span', $element->tag);
     $this->assertEquals('value', $element->text());
     $element = $document->createElement('span');
     $this->assertEquals('', $element->text());
 }
All Usage Examples Of DiDom\Document::createElement