Guntars Viciuss Guntars Viciuss - 1 year ago 122
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'.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download