getElementById() public method

Simple wrapper function that returns an element by the id.
public getElementById ( string $id ) : AbstractNode
$id string
return PHPHtmlParser\Dom\AbstractNode
Example #1
0
 public function testConfigStrict()
 {
     $dom = new Dom();
     $dom->setOptions(['strict' => true]);
     $dom->load('<div><p id="hey">Hey you</p> <p id="ya">Ya you!</p></div>');
     $this->assertEquals(' ', $dom->getElementById('hey')->nextSibling()->text);
 }
 public function testConfigLocalOverride()
 {
     $dom = new Dom();
     $dom->setOptions(['whitespaceTextNode' => false]);
     $dom->load('<div><p id="hey">Hey you</p> <p id="ya">Ya you!</p></div>', ['whitespaceTextNode' => true]);
     $this->assertEquals(' ', $dom->getElementById('hey')->nextSibling()->text);
 }
Example #3
0
 public function testGetElementById()
 {
     $dom = new Dom();
     $dom->load('<div class="all"><p>Hey bro, <a href="google.com" id="78">click here</a></div><br />');
     $this->assertEquals('<a href="google.com" id="78">click here</a>', $dom->getElementById('78')->outerHtml);
 }