Skip to content

Latest commit

 

History

History
77 lines (60 loc) · 1.6 KB

append-and-prepend.md

File metadata and controls

77 lines (60 loc) · 1.6 KB

append and prepend

<< Previous                                                              Next >>

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.

Syntax: append and prepend

$doc->Q([selector])->append([html-content]);
$doc->Q([selector])->prepend([html-content]);

$html

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

Example test code snippet

Click here to go to example test.