I’m trying to move my Reply Form from one comment block to another according to where Reply button was pushed.
For example I have this code.
<ul class="comments-list">
<li class="comment" id="'.$comComment->CommentID.'">
<div>Comment Content</div>
<a class="comment-reply-link"></a>
<ul>
<li>
<div>Comment Content</div>
<a class="comment-reply-link"></a>
</li>
</ul>
</li>
<li>
<div>Comment Content</div>
<a class="comment-reply-link"></a>
</li>
</ul>
And then reply form:
<div id="comment-reply">And Form HEre</div>
I know how to do it with display block and none but I’d like to avoid making Reply form in every comment block and hiding it.
Is it possible to do it with something like parentNode.insertBefore and parentNode.removeChild. or is there a better way to do that.
Would appreciate any help or related links.
Thank you.
Here’s how you would do it with jQuery:
http://jsfiddle.net/Cd4Xk/
without jQuery it is more difficult. this question led me to the eventual solution: How to do insert After() in JavaScript without using a library?
I also found this link helpful in solving this:
http://snipplr.com/view/2107/insertafter-function-for-the-dom/
Here’s a working solution:
http://jsfiddle.net/Cd4Xk/1/
and here is the code from that solution:
of course, you will need to add
onclick="javascript:replyForm(this)"to your links.Hope that helps.