javascript - Javacript - 'appendChild' on 'Node': parameter 1 is not of type 'Node' -
i can't solve (learning js), there other threads none helped me.
according 'mozilla':
adding node, simple:
// create new paragraph element, , append end of document body var p = document.createelement("p"); document.body.appendchild(p);
however, when that, get:
"... parameter 1 not of type node"
js code:
(function () { var mynode = document.queryselector('#shiny-pics .pixgrid ul'); mynode.addeventlistener("click", function(e) { if (e.target.tagname === 'img') { var myoverlay = document.createelement('div'); myoverlay.id = 'overlay'; document.body.appendchild('myoverlay'); /*console.log(typeof(myoverlay));*/ /*console.log(myoverlay.prototype.tostring());*/ } }, false); //image clicked })();
i've tried see type of var 'myoverlay' (with typeof) , says object.
and with: 'object.prototype.tostring', see first error says object not of type node. see commented code.
you're appending (or attempting append) string 'myoverlay'
, not node created. in first sample of code didn't write
document.body.appendchild('p');
you should write
document.body.appendchild(myoverlay);
Comments
Post a Comment