[jQuery] Re: Creating DOM elements on the fly

2007-08-18 Thread duma
Thanks!! Yes, indentation helps make this readable ;-) AnuragMishra wrote: > > > Thanks for the sample plugin code Sean, > > This looks like a really neat plugin, I'll have to take care of the > indentation though. Can get very messy at 3 levels if not written > well. > > Anurag > --

[jQuery] Re: Creating DOM elements on the fly

2007-08-18 Thread Anurag
Thanks for the sample plugin code Sean, This looks like a really neat plugin, I'll have to take care of the indentation though. Can get very messy at 3 levels if not written well. Anurag On Aug 17, 4:19 pm, duma <[EMAIL PROTECTED]> wrote: > Anurag, > > I've written a Dom element-creating plugin

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Sean Catchpole
I wrote a fun dom creation plugin, but in the end it's not much better than the built in dom creation: http://jqueryjs.googlecode.com/svn/branches/sean-dev/jquery.dom.js ~Sean

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread duma
Anurag, I've written a Dom element-creating plugin for jQuery. The documentation is here: http://www.pinkblack.org/itblog/?page_id=22 This is how its usage looks: var someNodes = $.create( "div", {}, [ "span", {"class": "MyText"}, ["Hi! How are you?"], "img", {"sr

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Pops
Thanks Sam and Byron for the dynamic DOM creation plugin references. Like a puzzle, this is all coming together now. Thanks! -- HLS On Aug 17, 11:27 am, Sam Collett <[EMAIL PROTECTED]> wrote: > There are also a few others:http://jquery.com/plugins/project/FlyDOM > > Easy DOM creation (which te

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Sam Collett
There are also a few others: http://jquery.com/plugins/project/FlyDOM Easy DOM creation (which technically does not require jQuery, just the presence of $ in the global namespace): http://mg.to/2006/02/27/easy-dom-creation-for-jquery-and-prototype jquery-dom.js http://www.pinkblack.org/itblog/?p

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Byron
I guess this is probably just a bit late (and will be even later due google not posting my replies until after 24-48 hours ) but if your interested i wrote a plugin for creating dom elements from json templates have a look at it here : http://jquery.com/plugins/project/appendDom --Byron

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Erik Beeson
Yes, the 'window' object is the "global" object that everything is a part of. The DOM for the page is under window.document (on FireFox anyways, starting to get into details that I don't know a lot about). If you were to do "window.$someVar" (no quotes) in your FireBug console, you'll find your n

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Pops
Nice Erik! Definitely how I like to code! Perfect generalize "unobstrusive" coding! I do have a question from the your previous response. If its not stored in DOM, then were is the variable stored? I'm not referring to local scoping, but in general, like so: var $someVar = null; $(d

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Erik Beeson
If you find yourself doing this kind of thing a lot, it might be handy to turn it into a plugin (totally off the top of my head and untested): (function($) { var _appendTo = $.fn.appendTo; $.fn.appendTo = function(parent, n) { if(n) { var id = this.attr('id');

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Erik Beeson
> I have to remember that a variable is a "node" in the DOM tree. Does > that mean that when it initially created, it is hidden? Not quite. When you create a DOM node from scratch, it exists in memory, but not as a part of "the DOM" (that is, the collection of DOM nodes that make up the page), an

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Pops
Michael replied: > A single node can't appear twice in the DOM. But you can easily clone a > node. > > http://docs.jquery.com/DOM/Manipulation#clone.28_deep_.29 Ok, thanks. One thing I partially disagree with that Simon fella and his excellent jQuery writeup, was the idea that if you can separa

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Pops
On Aug 17, 4:30 am, "Erik Beeson" <[EMAIL PROTECTED]> wrote: > Actually, technically, what I suggested wastes the original node since > it never gets inserted, just cloned. Maybe this would be slightly > better: > > function MakeEmailField(n) { > var $inputBox = $('').attr("type", "text"); >

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Pops
On Aug 17, 4:25 am, "Erik Beeson" <[EMAIL PROTECTED]> wrote: > You don't really want multiple fields with the same ID though, do you? > I think .clone() will help you: No, but I strategically and intentionally left that in to get this exact feedback. :-) Specifically, the id question, which dep

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Erik Beeson
Actually, technically, what I suggested wastes the original node since it never gets inserted, just cloned. Maybe this would be slightly better: function MakeEmailField(n) { var $inputBox = $('').attr("type", "text"); for(var i = 1; i < n; i++) { $inputBox.clone().attr("id","email

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Erik Beeson
You don't really want multiple fields with the same ID though, do you? I think .clone() will help you: function MakeEmailField(n) { var inputBox = $('').attr("type", "text"); for (i =0; i < n; i++) { inputBox.clone().attr("id","email"+i).appendTo('#myForm'); } } The initi

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Michael Geary
> Meaning, is this following valid? > > var inputBox = $('').attr("type", "text").attr("id", > "someText"); > . > . > inputBox.appendTo('#myForm'); > inputBox.appendTo('#myForm'); > inputBox.appendTo('#myForm'); > > In my testing, that doen't work. It only adds the first one. A si

[jQuery] Re: Creating DOM elements on the fly

2007-08-17 Thread Pops
On Aug 17, 2:49 am, "Karl Rudd" <[EMAIL PROTECTED]> wrote: > In the examples I gave the new element is "saved" to the variable > inputBox. So to add it to the DOM you will do something like what Erik > wrote, that is: > > inputBox.appendTo('#myForm'); > > The above appends it (that is, adds it

[jQuery] Re: Creating DOM elements on the fly

2007-08-16 Thread Karl Rudd
In the examples I gave the new element is "saved" to the variable inputBox. So to add it to the DOM you will do something like what Erik wrote, that is: inputBox.appendTo('#myForm'); The above appends it (that is, adds it as the last element) to an element with id="myForm". There are other

[jQuery] Re: Creating DOM elements on the fly

2007-08-16 Thread Pops
On Aug 17, 2:10 am, "Karl Rudd" <[EMAIL PROTECTED]> wrote: > It's already built in. For your example: > > var inputBox = $('').attr("type", "text").attr("id", "someText"); > Karl, Question, I've still learning jQuery, so please forgive me as I am not 100% sure if I will poise the question cor

[jQuery] Re: Creating DOM elements on the fly

2007-08-16 Thread Anurag
Feel like I hit a jackpot. Thanks! On Aug 17, 1:11 am, "Erik Beeson" <[EMAIL PROTECTED]> wrote: > The jQuery function $() can parse HTML, as can the various DOM > functions (append, prepend, appendTo, etc): > > $('').appendTo('#myForm'); > > --Erik > > On 8/16/07, Anurag <[EMAIL PROTECTED]> wrot

[jQuery] Re: Creating DOM elements on the fly

2007-08-16 Thread Erik Beeson
The jQuery function $() can parse HTML, as can the various DOM functions (append, prepend, appendTo, etc): $('').appendTo('#myForm'); --Erik On 8/16/07, Anurag <[EMAIL PROTECTED]> wrote: > > Hi, > > I am a jQuery beginner. I am working on an application for which I > need to create DOM element

[jQuery] Re: Creating DOM elements on the fly

2007-08-16 Thread Karl Rudd
It's already built in. For your example: var inputBox = $('').attr("type", "text").attr("id", "someText"); Or even: var inputBox = $(''); Karl Rudd On 8/17/07, Anurag <[EMAIL PROTECTED]> wrote: > > Hi, > > I am a jQuery beginner. I am working on an application for which I > need to create