2011-06-18 9 views

答えて

3

は試してみてください。

$img->parentNode->insertBefore($before, $img); 

insert関数の引数(「参照ノード」)として$imgを追加するには、明示的階層に新しいノードを挿入する場所に挿入伝えます。それ以外の場合、ドキュメントは単に「子に追加されました」と言います。つまり、新しいノードが親の子の最後のノードになります。

余分な引数なし

<span> <-- parentNode 
     <b>This is some text before the image</b> 
     <img ...> <--- $img node 
     <i>This is some text after the image</b> 
    </span> 

、あなたが得る:引数WITH

<span> 
    <b>...</b> 
    <img ...> 
    <i>...</i> 
    new text node here <-- appended to parent Node's children, e.g. last 
    </span> 

を、あなたが得る:

<span> 
    <b>...</b> 
    new text node here <--the "before" position 
    <img ...> 
    <i>...</i> 
    </span> 
+0

私はそれにあなたの説明のために感謝しました! :D – Teiv

関連する問題