jquery-dom.js
May 31st, 2007
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!
hi,
download link broken.
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?
Link to js file doesn’t work…
Hey man - don’t suppose you wanna get the link to download jquery-dom.js working again by any chance, do you?
Thanks!
Hey there, your script download link is now 404. What happened to it?
Your download link isn’t working. However the concept looks great.
Cheers