this
对应一个特定的div。
我想使用此代码在其祖父母之后插入一段代码,但它似乎不起作用:this.parentNode[0].parentNode[0].insertAfter(newrespondform);
如果需要,我可以提供更多代码,但在尝试调试后,我很确定问题出在此处。我怎么能写它使它工作?我不能向祖父母添加一个 ID 来选择它。
感谢您的帮助:)
编辑 - 这是在页面加载时加载的整个代码:
function comrespond(){
function addresform(){
var resid = this.getAttribute('id'),
grandParent = this.parentNode.parentNode,
newrespondform = '<div class="commentresponse"><span></span><span><p class="author">Leave a reply:</p><form id="commentform" action="http://split.snippetspace.com/wp-comments-post.php" method="post" onsubmit="addcomment(); return false;"><input id="author" aria-required="true" name="author" type="text" placeholder="Your name"/><input id="email" aria-required="true" name="email" type="text" placeholder="Email address" /><textarea id="comment" aria-required="true" name="comment" rows="8"></textarea><input id="submit" name="submit" type="submit" value="Post Comment" /><input id="comment_post_ID" name="comment_post_ID" type="hidden" value="'+resid+'" /></form></span></div>';
grandParent.parentNode.insertBefore(newrespondform, grandParent.nextSibling);
}
var responsebtn = document.getElementsByClassName('comment-reply-link');
for(var i = 0; i < responsebtn.length; i++){
bindEvt(responsebtn[i], "click", addresform);
};}
的HTML:
<div>
<span></span>
<span>
<p class="author">Christopher</p>
<div class="comment-reply-link" id="106"></div>
<p>test comment 2 to see if it increments!</p>
</span>
</div>