Guntars Viciuss Guntars Viciuss - 3 months ago 27
Javascript Question

Javascript for in setAttribute

At school my teacher changed my code to example down below
and it's not working and I can't understand how it works and fix it.



function _$(e, attrs) {
var el = document.createElement(e);
for(a in attrs){
el.setAttribute(a, attrs[a]);
}
}

var $taskMain = _$("section", { "class": "sdfjsf", "id": "taskId", "data-id-number": "sajfsaf"});

//and i have error
//template.js:80 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
currentCollon.appendChild($taskMain);




Answer

I think you're missing a return el; at the end of your _$ function.