JavaScript document.createElement() Alternative

by Kyle Hayes on July 4th, 2006

I haven’t blogged in a while because I have been so busy getting ready for the wedding and things with my new job at Boeing as well. Which is partially the reason why I am blogging about this. I working on a project that I would like to add dynamic type functions into. After learning about creating DOM objects dynamically, I realized that the createElement and setAttribute functions should have been combined to make it easier. 

I am by no means a Javascript guru so if anybody would like to explain the disadvantages to my function then please elaborate in the comments. The function I created is simply called createElement and it shouldn’t interfere with the other one as the other is part of the document class. An example of how the function can be used is as follows:


var txtbox = createElement('input','name=myTextBox','type=text','value=Your Text Here');

which would return the following tag element:

Download the code using the download link below.

Popular Posts

From JavaScript

2 Comments
  1. Bharat permalink

    HiKyle ,
    An excellent function fullfill lot of requirment, I have just made a alteration in function instead of
    items.length()>1
    it should be only
    items>1

    Thanks and Regards,
    Bharat

  2. Good find Bharat. Thanks

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS