The html()
method sets or returns the content (innerHTML) of the selected elements.
When this method is used to return content, it returns the content of the FIRST matched element.
When this method is used to set content, it overwrites the content of ALL matched elements.
Tip: text()
works the same way as html()
, except that it is used to set or return only text content.
Return content:
$doc->Q([selector])->html();
$doc->Q([selector])->text();
Set content:
$doc->Q([selector])->html([html-content]);
$doc->Q([selector])->text([text-content]);
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Php
```php
<?php
include "../src/webparser.php";
$doc = new WebParser();
$doc->loadHTML($html);
$doc->Q("p:first")->html("<i>Hello world!</i>");
$text = $doc->Q("p:first")->text();
$doc->Q("p[2]")->text("<b>$text</b>");
$doc->output();
```
Output
```html
<p><i>Hello world!</i></p>
<p><b>this is a paragraph</b></p>
```
Click here to go to example test.