vForums Support Banner


Visit vForums

 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Database of Codes/Hacks/Mods :: CreateElement - View Topic
Topic Rating: *****
Printable View
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
CreateElement (3rd Apr 08 at 10:02pm UTC)
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}
3flash
New Member
*

[Avatar]
Never Get To Old To Learn!

Posts: 3
Status: Offline
Gender: Male
Location: Tunica Ms
Age: 78
Joined:  
Reputation: 0%  


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

Thanks
Flash

ImageImageImage
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
Re: CreateElement (25th Feb 09 at 4:03pm UTC)
It's a 'snippet' really that a coder would use in their codes! {Smile}
Simie
New Member
*

Posts: 20
Status: Offline
Joined:  
Reputation: 0%  


pm
Re: CreateElement (16th Apr 09 at 1:04pm UTC)
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?
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
Re: CreateElement (17th Apr 09 at 8:02am UTC)
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}
 
Simie
New Member
*

Posts: 20
Status: Offline
Joined:  
Reputation: 0%  


pm
Re: CreateElement (17th Apr 09 at 9:50pm UTC)
 
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.
 Printable View

All times are GMT+0 :: The current time is 3:07pm
Page generated in 1.5653 seconds
This Forum is Powered By vForums (v2.4)
Create a Forum for Free | Find Forums