Insert HTML from script - pagebreak problem

Hi,

I need to generate HTML code in script (no problem), insert it in print document (also not a problem), and enable page break in the middle of generated HTML (problem).

Generated HTML is something like

<span>Header 1</span>
<ul>
   <li>item 1</li>
   <li>item 2</li>
   <li>item 3</li>
</ul>
<span>Header 2</span>
<ul>
   <li>item 1</li>
   <li>item 2</li>
   <li>item 3</li>
</ul>

I’ve created placeholder in document like

<p>Some text</p>
@placeholder@
<p>Anohter text</p>

When I create script that will look for @placeholder@ and write “results.html(generatedHTML)” in script it inserts HTML in correct place, but inserted HTML is enclosed in SPAN element and it won’t break that HTML across multiple pages.

Is this correct procedure to insert HTML or should I use some other technic?

Thanks.

I suggest to use replaceWith() instead of html(). The latter is used to set the inner html of an element. In case of text search replace this will wrap the text found with a first (because there is no element).

The following should solve the problem.

results.replaceWith( generatedHTML );

Erik

1 Like