|
Description: Allows you to create an element and assign it several attributes at once. I'll probably rewrite this later. Could come in handy working with objects in general. Syntax: createElement( string, { parameters}) function createElem(a, b) { if(a.constructor == String) a = document.createElement(a); for(var x in b) { if(b[x].constructor == Object) { createElem(a[x], b[x]); continue; } a[x] = b[x]; } return a; }Example: (added the line-breaks so it'd be easier to see) var i = createElem("td", { width: "100%", height: 200, colSpan: 2, className: "menubg", style: { color: "#FFFFFF", backgroundColor: "#000000" } });
Last Edit: Apr 18, 2007 19:30:37 GMT by Aaron
|
|
|
|
not bad
|
|
|
|
|
Why did you name the for loop by the way? There's technically no need.
Last Edit: Apr 16, 2007 22:35:08 GMT by Chris
|
|
|
|
|
Well, let's say style object comes into play. If I didn't tell the outer loop to continue, it would attempt to execute this line: a[x] = b[x]; Translating to, a.style = b.style Edit: I got you know. When I was playing around with it earlier, that if was a for. Guess I forgot to remove it.
Last Edit: Apr 16, 2007 23:14:15 GMT by Aaron
|
|
|
|
Not like it causes a different in speed in the script, it just made me curious if there was something like a bug in old browsers I didn't know of or something.
|
|
|
|
|
No, just a case where I had two loops and had to continue the outer.
|
|
|