The append()
method inserts specified content at the end of the selected elements.
Tip: To insert content at the beginning of the selected elements, use the prepend()
method.
$doc->Q([selector])->append([html-content]);
$doc->Q([selector])->prepend([html-content]);
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>
Php
<?php
include "../src/webparser.php";
$doc = new WebParser();
$doc->loadHTML($html);
$doc->Q("ol")->append("<li>Appended html</li>");
$doc->Q("ol")->prepend("<li>Prepended html</li>");
$doc->output();
Output
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<ol>
<li>Prepended html</li>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>Appended html</li>
</ol>
Click here to go to example test.