vForums Support > Programming & Coding :: Database of Codes/Hacks/Mods :: > CreateElement

CreateElement - Posted By Michael (wrighty) on 3rd Apr 08 at 10:02pm
This is a snippet

This is a function that will allow you to create an element and assign attributes without having to go through lines and lines of coding!



function create(x, y) {
    if(x.constructor == String){
        x = document.createElement(x);
    }
    for(var a in y) {
        if(y[a].constructor == Object) {
            this.create(x[a], y[a]);
            continue;
        }
        x[a] = y[a];
    }
    return x;
};


Example of usage:
Creating a td
create('td',{colSpan: "2", vAlign: "top"});
That has Colspan of 2 and valign top.

create('div',{style: {backgroundColor: "#FF0000"}, align: "center"});

You get the idea! {Smile}

Re: CreateElement - Posted By 3flash (3flash) on 25th Feb 09 at 3:42pm
I get the Idea however I would Really like to know Where to Put it at? Header,footer,Global or Main?

Thanks
Flash

Re: CreateElement - Posted By Michael (wrighty) on 25th Feb 09 at 4:03pm
It's a 'snippet' really that a coder would use in their codes! {Smile}

Re: CreateElement - Posted By Simie (simie) on 16th Apr 09 at 1:04pm
Code:
 
  1.  function createElement(a, b) {
  2.       if(a.constructor == String)
  3.             a = document.createElement(a);
  4.       for(var x in b) {
  5.             if(b[x].constructor == Object) {
  6.                   createElement(a[x], b[x]);
  7.                   continue;
  8.             }
  9.             a[x] = b[x];
  10.       }
  11.       return a;
  12. }
 


http://forum.smangii.com/index.cgi?board=pbsupport&action=display&thread=6636&page=1#67534


This code is exactly the same as that, except a few changed variable names. Rip?

Re: CreateElement - Posted By Michael (wrighty) on 17th Apr 09 at 8:02am
So someone's not allowed to read a code - and then recode it? {Unsure}

*sigh* if that's what someone isn't allowed to do! {Unsure}
 

Re: CreateElement - Posted By Simie (simie) on 17th Apr 09 at 9:50pm
 
So someone's not allowed to read a code - and then recode it? {Unsure}

*sigh* if that's what someone isn't allowed to do! {Unsure}
 

 Copying a code and changing a few variable names is not taking inspiration from something, its stealing it.