<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: DOMTool: Given HTML generate DOM methods</title>
	<atom:link href="http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Wed, 17 Mar 2010 23:37:29 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Michael Geary</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-222601</link>
		<dc:creator>Michael Geary</dc:creator>
		<pubDate>Fri, 01 Dec 2006 20:31:30 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-222601</guid>
		<description>Actually, James, with DOMTool you can save references to the objects as they are created. In fact, it looks like the generated code creates a unique variable name for each DOM element, so you are all set.

Mine also allows you to save references to inner objects. If you wanted the inner A element from my example, you&#039;d do this:

&lt;code&gt;
var a;
$.DIV({ id:&#039;test&#039;, &#039;class&#039;:&#039;outer&#039; },
    $.SPAN({ &#039;class&#039;:&#039;inner&#039; },
        a = $.A({ href:&#039;example.html&#039;, title:&#039;Howdy&#039; },
            &#039;Click me&#039; ) ) );
&lt;/code&gt;

Olsowâ€™s function doesn&#039;t let you save references to inner elements - it just gives you a jQuery object for the topmost element(s).</description>
		<content:encoded><![CDATA[<p>Actually, James, with DOMTool you can save references to the objects as they are created. In fact, it looks like the generated code creates a unique variable name for each DOM element, so you are all set.</p>
<p>Mine also allows you to save references to inner objects. If you wanted the inner A element from my example, you&#8217;d do this:</p>
<p><code><br />
var a;<br />
$.DIV({ id:'test', 'class':'outer' },<br />
    $.SPAN({ 'class':'inner' },<br />
        a = $.A({ href:'example.html', title:'Howdy' },<br />
            'Click me' ) ) );<br />
</code></p>
<p>Olsowâ€™s function doesn&#8217;t let you save references to inner elements &#8211; it just gives you a jQuery object for the topmost element(s).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Geary</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-222484</link>
		<dc:creator>Michael Geary</dc:creator>
		<pubDate>Fri, 01 Dec 2006 19:19:31 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-222484</guid>
		<description>Hmm... A comment system on a blog frequented by coders should allow indentation! Assume proper indentation in the code above... :-)</description>
		<content:encoded><![CDATA[<p>Hmm&#8230; A comment system on a blog frequented by coders should allow indentation! Assume proper indentation in the code above&#8230; :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Geary</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-222483</link>
		<dc:creator>Michael Geary</dc:creator>
		<pubDate>Fri, 01 Dec 2006 19:18:32 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-222483</guid>
		<description>Thanks, James.

To compare the different techniques, let&#039;s try a more interesting bit of HTML code:

&lt;code&gt;
&lt;div id=&quot;test&quot; class=&quot;outer&quot;&gt;
    &lt;span class=&quot;inner&quot;&gt;
        &lt;a href=&quot;example.html&quot; title=&quot;Howdy&quot;&gt;
            Click me
        &lt;/a&gt;
    &lt;/span&gt;
&lt;/div&gt;
&lt;/code&gt;

Here&#039;s the output from DOMTool:

&lt;code&gt;
var div1=document.createElement(&#039;DIV&#039;);
div1.className=&#039;outer&#039;;
div1.setAttribute(&#039;id&#039;,&#039;test&#039;);
var span1=document.createElement(&#039;SPAN&#039;);
span1.className=&#039;inner&#039;;
div1.appendChild(span1);
var a1=document.createElement(&#039;A&#039;);
a1.setAttribute(&#039;title&#039;,&#039;Howdy&#039;);
a1.setAttribute(&#039;href&#039;,&#039;example.html&#039;);
span1.appendChild(a1);
var txt1=document.createTextNode(&#039;Click me\n		&#039;);
a1.appendChild(txt1);
&lt;/code&gt;

Here&#039;s how you would code it with my DOM creation functions:

&lt;code&gt;
$.DIV({ id:&#039;test&#039;, &#039;class&#039;:&#039;outer&#039; },
    $.SPAN({ &#039;class&#039;:&#039;inner&#039; },
        $.A({ href:&#039;example.html&#039;, title:&#039;Howdy&#039; },
            &#039;Click me&#039;
        )
    )
);
&lt;/code&gt;

And here is how it be using Olsow&#039;s DOM creation function (posted in the comments to my page that James referenced):

&lt;code&gt;
$.create(
    &#039;div&#039;, { id:&#039;test&#039;, &#039;class&#039;:&#039;outer&#039; }, [
        &#039;span&#039;, { &#039;class&#039;:&#039;inner&#039; }, [
            &#039;a&#039;, { href:&#039;example.html&#039;, title:&#039;Howdy&#039; }, [
                &#039;Click me&#039;
            ]
        ]
    ]
);
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Thanks, James.</p>
<p>To compare the different techniques, let&#8217;s try a more interesting bit of HTML code:</p>
<p><code><br />
&lt;div id="test" class="outer"&gt;<br />
    &lt;span class="inner"&gt;<br />
        &lt;a href="example.html" title="Howdy"&gt;<br />
            Click me<br />
        &lt;/a&gt;<br />
    &lt;/span&gt;<br />
&lt;/div&gt;<br />
</code></p>
<p>Here&#8217;s the output from DOMTool:</p>
<p><code><br />
var div1=document.createElement('DIV');<br />
div1.className='outer';<br />
div1.setAttribute('id','test');<br />
var span1=document.createElement('SPAN');<br />
span1.className='inner';<br />
div1.appendChild(span1);<br />
var a1=document.createElement('A');<br />
a1.setAttribute('title','Howdy');<br />
a1.setAttribute('href','example.html');<br />
span1.appendChild(a1);<br />
var txt1=document.createTextNode('Click me\n		');<br />
a1.appendChild(txt1);<br />
</code></p>
<p>Here&#8217;s how you would code it with my DOM creation functions:</p>
<p><code><br />
$.DIV({ id:'test', 'class':'outer' },<br />
    $.SPAN({ 'class':'inner' },<br />
        $.A({ href:'example.html', title:'Howdy' },<br />
            'Click me'<br />
        )<br />
    )<br />
);<br />
</code></p>
<p>And here is how it be using Olsow&#8217;s DOM creation function (posted in the comments to my page that James referenced):</p>
<p><code><br />
$.create(<br />
    'div', { id:'test', 'class':'outer' }, [<br />
        'span', { 'class':'inner' }, [<br />
            'a', { href:'example.html', title:'Howdy' }, [<br />
                'Click me'<br />
            ]<br />
        ]<br />
    ]<br />
);<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Cook</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-222295</link>
		<dc:creator>James Cook</dc:creator>
		<pubDate>Fri, 01 Dec 2006 17:10:16 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-222295</guid>
		<description>One drawback is not being able to assign JS vars to elements as they are created. I much prefer the approach published by Michael Geary and inspired by MochiKit.DOM:

http://mg.to/topics/programming/javascript/jquery

It really makes creating DOM fragments much, much simpler.</description>
		<content:encoded><![CDATA[<p>One drawback is not being able to assign JS vars to elements as they are created. I much prefer the approach published by Michael Geary and inspired by MochiKit.DOM:</p>
<p><a href="http://mg.to/topics/programming/javascript/jquery" rel="nofollow">http://mg.to/topics/programming/javascript/jquery</a></p>
<p>It really makes creating DOM fragments much, much simpler.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vijay Chakravarthy</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-220524</link>
		<dc:creator>Vijay Chakravarthy</dc:creator>
		<pubDate>Thu, 30 Nov 2006 21:36:23 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-220524</guid>
		<description>This is neat. I was thinking of writing something like this myself. Ideally, one should be able to do dojo like attachpoints inside the html via annotations, and have the code create equivalent variables that are visible externallly. This will then be  a simpler static version of dojoj widgets..</description>
		<content:encoded><![CDATA[<p>This is neat. I was thinking of writing something like this myself. Ideally, one should be able to do dojo like attachpoints inside the html via annotations, and have the code create equivalent variables that are visible externallly. This will then be  a simpler static version of dojoj widgets..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-220206</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Thu, 30 Nov 2006 17:13:03 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-220206</guid>
		<description>Sounds a lot like Jack yui-ext DOMHelper object (www.jackslocum.com)  which does this and supports templated building of repeating elements.  He also has a blog post about performance of innerHTML vs this type of approach.</description>
		<content:encoded><![CDATA[<p>Sounds a lot like Jack yui-ext DOMHelper object (www.jackslocum.com)  which does this and supports templated building of repeating elements.  He also has a blog post about performance of innerHTML vs this type of approach.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Holton</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-220172</link>
		<dc:creator>Mark Holton</dc:creator>
		<pubDate>Thu, 30 Nov 2006 16:34:02 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-220172</guid>
		<description>Really cool.  This is going to save me some time, thanks!</description>
		<content:encoded><![CDATA[<p>Really cool.  This is going to save me some time, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Schiller</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-220122</link>
		<dc:creator>Scott Schiller</dc:creator>
		<pubDate>Thu, 30 Nov 2006 16:09:02 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-220122</guid>
		<description>Very interesting! That is quite something. ;)

I&#039;m personally a fan of cloning HTML templates, (grabbing a collection of nodes and using cloneNode(true),) which would also work with the HTML-based approach given here. (This was used extensively for Yahoo! Photos and worked quite well.)

You may still have to modify each instance slightly for your uses, but the structure would be left intact - and that saves you a lot of time. It&#039;s also very simple if someone wants to modify your template structure, since it&#039;s HTML! I&#039;ve learned over the years that it seems best to leave HTML where it works best (as HTML), and not to create big complex structures of it using Javascript (but cloning and extending/customising with JS where appropriate.)</description>
		<content:encoded><![CDATA[<p>Very interesting! That is quite something. ;)</p>
<p>I&#8217;m personally a fan of cloning HTML templates, (grabbing a collection of nodes and using cloneNode(true),) which would also work with the HTML-based approach given here. (This was used extensively for Yahoo! Photos and worked quite well.)</p>
<p>You may still have to modify each instance slightly for your uses, but the structure would be left intact &#8211; and that saves you a lot of time. It&#8217;s also very simple if someone wants to modify your template structure, since it&#8217;s HTML! I&#8217;ve learned over the years that it seems best to leave HTML where it works best (as HTML), and not to create big complex structures of it using Javascript (but cloning and extending/customising with JS where appropriate.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-220068</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Thu, 30 Nov 2006 15:32:05 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-220068</guid>
		<description>I was actually thinking of writing something like this myself. Guess that I don&#039;t have to now.</description>
		<content:encoded><![CDATA[<p>I was actually thinking of writing something like this myself. Guess that I don&#8217;t have to now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mario</title>
		<link>http://ajaxian.com/archives/domtool-given-html-generate-dom-methods/comment-page-1#comment-220002</link>
		<dc:creator>Mario</dc:creator>
		<pubDate>Thu, 30 Nov 2006 14:48:34 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/domtool-given-html-generate-dom-methods#comment-220002</guid>
		<description>I like the idea. Some will say, &quot;Well, what about innerHTML?&quot; This isnt for replacing the simple innerHTML (i use innerHTML whenever possible). Lets say you have a complex dynamically made chunk of DOM goodness and you just dont want to have to spend all the time crating the dom. You drop it in, then pick out the peaces you need.</description>
		<content:encoded><![CDATA[<p>I like the idea. Some will say, &#8220;Well, what about innerHTML?&#8221; This isnt for replacing the simple innerHTML (i use innerHTML whenever possible). Lets say you have a complex dynamically made chunk of DOM goodness and you just dont want to have to spend all the time crating the dom. You drop it in, then pick out the peaces you need.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
