jquery-dom.js

jquery-dom.js is a library for generating DOM elements for use in jQuery code. The primary function is $.create, which returns a DOM element or an array of DOM elements. It is used as follows:


var child_node =
   $.create("div", {"class": "a_child big_text bold_text"}, ["stuff!"]);

var parent_node =
   $.create("div", {"class": "a_parent"}, [child_node,
      "div", {"class": "some_other_stuff"}, ["here is where the other stuff goes"]]);

$("#stuff_container").append(parent_node);

/* You don't have to create nodes separately to
 * include them as children! */
var some_other_nodes =
   $.create(
      "div", {}, [
         "span", {"class": "ConsultantInvolved"}, [consultantName],
         "img", {"src": "Images/delete.gif", "class": "DeleteInvolvedConsultant"}, []]);

So, $.create is used this way:

$.create(tag_name, attributes, [children...]);

One important thing to remember is that, when you specify a node, you always specify things in the above order — that is, tag_name followed by an attributes hash, followed by an array of children. You must do this even if the children array is empty.

Hopefully this is pretty clear! Leave me comments if it isn’t :-)

This work is inspired by Oslow’s work in the comments of this page.

Note: You must include the jQuery library for this to work!

  1. mrt
    May 20th, 2008 at 01:07 | #1

    hi,

    download link broken.

  2. owerio
    May 31st, 2008 at 12:24 | #2

    Hello. Thanks for the plugin. I want to create element nodes for subframe documents by coding on top document scope. How can I achieve this using your plugin?

  3. Bob
    June 1st, 2008 at 17:36 | #3

    Link to js file doesn’t work…

  4. dude
    September 21st, 2008 at 06:31 | #4

    Hey man - don’t suppose you wanna get the link to download jquery-dom.js working again by any chance, do you?

    Thanks!

  5. Andrew Powell
    October 29th, 2008 at 11:00 | #5

    Hey there, your script download link is now 404. What happened to it?

  6. December 25th, 2008 at 14:19 | #6

    Your download link isn’t working. However the concept looks great.
    Cheers

  1. No trackbacks yet.