0

I am looking for a way, how I can insert a Node at the very beginning of a node, no matter, what there is in (I am making an epub).

Example:

<p>Some test<a href="...">some link</a> Some more text<span id="page_10"></span></p>

Now I want to insert there something, it should look like:

<p><myInsertedNode>My content</myInsertedNode>Some test<a href="...">some link</a> Some more text<span id="page_10"></span></p>

I wanted to use insertBefore, but it doesn't work. because I have to give a Node for it. My "<p>" does not allways have some inner Notes, but can have them. So the best I could archive, was to insert it before the "<p>", but this is not, what I intend to do.

Michèle S.
  • 304
  • 1
  • 3
  • 7
  • 1
    possible duplicate of [Insert created element at start of html tag using PHP DOM](http://stackoverflow.com/questions/3180113/insert-created-element-at-start-of-html-tag-using-php-dom) –  Dec 23 '14 at 21:26
  • Not really, because I need to insert the element before the nodeValue, too! – Michèle S. Dec 23 '14 at 21:39
  • I set this up on PHPFiddle and it works well. It's also the answer you seem to have found for yourself below. –  Dec 23 '14 at 22:03
  • `Some test` would be a text node in the DOM. find that text node, then you can use `node::insertBefore()` – Marc B Dec 23 '14 at 22:03

1 Answers1

0

OK, after 3 hours of looking for, I found a shockingly easy awnser:

Use as second parameter of insertBefore firstChild!

Michèle S.
  • 304
  • 1
  • 3
  • 7