user1173517 user1173517 - 1 month ago 7
Javascript Question

Argument 1 of Node.appendChild does not implement interface Node

I am new to JavaScript, and i cannot figure out what are interface nodes? Below is my code with the error

Panel = function () {
var popUpDiv = document.getElementById("firewall-content");
var panelDiv = $("<div></div>").addClass("side_panel");
popUpDiv.appendChild(panelDiv);
};

Answer

appendChild is a native DOM method and only accepts DOM nodes as a parameter. The element you're trying to append (panelDiv) is a jQuery object, not a DOM element. You can either append the DOM element:

Panel = function () {
   var popUpDiv = document.getElementById("firewall-content");
   var panelDiv = $("<div></div>").addClass("side_panel")[0];
   popUpDiv.appendChild(panelDiv);
};

Or use jQuery's built in functions all the way through your code (which you should anyway if you're using jQuery):

Panel = function () {
   var popUpDiv = $("#firewall-content");
   var panelDiv = $("<div></div>").addClass("side_panel");
   popUpDiv.append(panelDiv);
};