Uncaught Not Found错误:无法执行' insertBefore'在' Node'

时间:2014-10-18 12:21:46

标签: javascript jquery

我有一个问题:

  

Uncaught NotFoundError:无法执行' insertBefore' on'节点':插入新节点之前的节点不是该节点的子节点。

在此文件中:

var AnimeBlock = {
 info: null,
 blocks: null,
 container: null,
 infoContent: null,

 init: function() {
    var i;
    this.info = document.getElementById('anime_info');
    this.infoContent = document.getElementById('anime_info_content');
    this.container = document.getElementById('anime-list');
    this.blocks = this.container.querySelectorAll('[data-type="anime"]');
    for (i = this.blocks.length - 1; i >= 0; i--) {
        this.prepareBlock(this.blocks[i], i);
    }                   
},

prepareBlock: function(block, position) {
    var place = position + (3 - position % 3),
        id = block.getAttribute('data-anime-list'),
        info = block.querySelector('script[type="x-template"][data-anime-type="info"]').innerHTML;
        self = this;
    block.onclick = function() {
        $('.anime_info').css("display","block");
        self.infoContent.innerHTML = info;
        self.container.insertBefore(self.info, self.blocks[place]);
    };
  }
}; 

HTML

<div class="anime_news" id="anime-list">
        <!--<div style="display: none;">-->
            <div id="anime_info">
                <div style="clear: both;"></div>
                <div id="anime_info_content" class="anime_info">

                </div>
            </div>
        <!--</div>-->

请帮帮我。

1 个答案:

答案 0 :(得分:0)

显然,self.blocks[place]不属于self.container。但是,自self.info以来,我认为你想要:

self.container.insertBefore(self.blocks[place], self.info);

(第一个参数是要插入的新节点)