The replaceWith()
method replaces selected elements with new HTML content.
$doc->Q([selector])->replaceWith([html/xml-content]);
<div class="container">
<div class="inner first">Hello</div>
<div class="inner second">And</div>
<div class="inner third">Goodbye</div>
</div>
Php
```php
<?php
include "../src/webparser.php";
$doc = new WebParser();
$doc->loadHTML($html);
$doc->Q("div.second")->replaceWith("<h2>New heading</h2>");
$doc->output();
```
Output
```html
<div class="container">
<div class="inner first">Hello</div>
<h2>New heading</h2>
<div class="inner third">Goodbye</div>
</div>
```
Click here to go to example test.