getElementById is specifically for retrieving DOM elements by their id attribute. Try this instead:
this.widgetDoc.getElementById("legendNode").appendChild(myNode);
For other ways of retrieving DOM nodes, look into querySelector and querySelectorAll.