Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.41 KB

replacewith.md

File metadata and controls

67 lines (51 loc) · 1.41 KB

replaceWith

<< Previous                                                              Start >>

The replaceWith() method replaces selected elements with new HTML content.

Syntax: replaceWith

$doc->Q([selector])->replaceWith([html/xml-content]);

$html

<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>
```

Example test code snippet

Click here to go to example test.