User:Bawolff/sandbox/stuff.js

//random functions that are useful.

function new_element (name, attributes) { //Create element, and attributes, and optionally add to tree // call as new_element(element name to create(string), attributes of element (object), optionally element to append as a child to) if (name) { var elm = document.createElement(name); } else { return null; } //set attributes if (typeof(attributes) == "object") { for (var i in attributes) { elm.setAttribute(i, attributes[i]); } } else { return null; } //attach to tree (but only if third argument given) if (arguments[2]) { var appendState = arguments[2].appendChild(elm) if (!appendState) { throw new Error("JS Error (quizPostScore-new_element): Can not find element to append new element to. (element)"); } } return elm; }