Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
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

(¯`•DregondRahl•._)

(¯`•DregondRahl•._) Avatar
Remanifesting-Eternal

***
Dedicated Member

239


September 2006
not bad :)




Chris

Chris Avatar

******
Head Coder

19,519


June 2005
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

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
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. :P Guess I forgot to remove it.


Last Edit: Apr 16, 2007 23:14:15 GMT by Aaron

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
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.

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
No, just a case where I had two loops and had to continue the outer.

newBookmarkLockedFalling