javascript - Parameters in Object function passed, but Executed as Null -



javascript - Parameters in Object function passed, but Executed as Null -

i've made object personal js library, reason on 1 of pages 1 of function parameters beingness weird.

the parameters passing, homecoming values when logged, 1 time parid gets passed getelementbyid method, gets returned null.

html:

<body id="body"> <header> <h1>title</h1> </header> <article id="run"></article> </body>

javascript:

library code:

var doc = { make: function (tagname, id, parid, txt){ // creates & appends elements, sets id, initializes , sets text in textnodes // var body = document.getelementsbytagname('body')[0]; var cvar = document.createelement(tagname); if(id.length !== 0){ cvar.setattribute('id', id); } if(parid === undefined || parid === null ){ document.body.appendchild(cvar); } else if(parid.length === 0){ // } else{ console.log(parid); // **here** returns passed argument var paridsel = document.getelementbyid(parid); // happens here ?? console.log(paridsel); // **also here** returns "null" paridsel.appendchild(cvar); // "uncaught typeerror: cannot read property 'appendchild' of null" } if(txt !== undefined){ var getcvar = cvar; var textnode = document.createtextnode(txt); getcvar.appendchild(textnode); } // if(code !== undefined){ // var getcvar = cvar; // getcvar.innerhtml = code; // } homecoming doc; }, //etc...

method calling property:

doc.make('p','content','run','hello world');

any observable problem? again, first , time problem has appeared; have library working on page using exact same script, no issues.

javascript object null arguments

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -