Note that there are some explanatory texts on larger screens.

plurals
  1. POremoving child from a child
    text
    copied!<p>I am having trouble removing the child of a child of an object created using JS.</p> <p>Basically once I create a comment object I appendChild(replyBox) to it. Inside the replyBox there is a cancel button which is supposed to completely delete the replyBox. </p> <p>Here is the code : </p> <pre><code> function Comment(message){ var self = this; var message = message; var comment = document.createElement("li"); comment.id = "comment"; comment.style = "display: none;"; comment.textContent = message; createButtons(comment); var parent = document.getElementById("wall"); parent.appendChild(comment); return comment; } function deleteComment(comment){ var parent = document.getElementById("wall"); parent.removeChild(comment); } function newReply(comment){ var buttons = comment.getElementsByTagName("input"); buttons.item(0).disabled="disabled"; var replyBox = document.createElement("div"); replyBox.id="replyBox"; var replyTxt = document.createElement("input"); replyTxt.type="text"; replyTxt.value="Write a reply"; replyTxt.onfocus = "if(this.value==this.defaultValue) this.value='';" ; replyTxt.onblur="if(this.value=='') this.value=this.defaultValue;"; replyBox.appendChild(replyTxt); createButtons(replyBox); comment.appendChild(replyBox); } function createButtons(parent){ var button = document.createElement("input"); button.type = "submit"; if(parent.id=="comment"){ var reply = button.cloneNode(); reply.value = "reply"; reply.addEventListener("click", function(){newReply(parent)},false); parent.appendChild(reply); var deleteBtn = button.cloneNode(); deleteBtn.value = "delete"; deleteBtn.addEventListener("click", function(){deleteComment(parent)},false); parent.appendChild(deleteBtn); } else{ var submitBtn = button.cloneNode(); submitBtn.value = "submit"; //reply.addEventListener("click", function(){newReply(parent)},false); parent.appendChild(submitBtn); var cancel = button.cloneNode(); cancel.value = "cancel"; cancel.addEventListener("click", function(){cancel(parent)},false); parent.appendChild(cancel); } } function cancel(replyBox){ replyBox.parentNode.removeChild(replyBox); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload