User:Bawolff/sandbox/stuff.js

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

//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;
}