<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Latent Motion &#187; jquery clone</title>
	<atom:link href="http://www.latentmotion.com/tag/jquery-clone/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.latentmotion.com</link>
	<description>Usability, Design and Front-Side Programming</description>
	<lastBuildDate>Tue, 27 Jul 2010 05:40:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using jQuery Clone to Add Dynamic Data</title>
		<link>http://www.latentmotion.com/using-jquery-clone-to-add-dynamic-data/</link>
		<comments>http://www.latentmotion.com/using-jquery-clone-to-add-dynamic-data/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 16:00:02 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[delicious feed]]></category>
		<category><![CDATA[dynamic data]]></category>
		<category><![CDATA[jquery clone]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[rolling delicious]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=319</guid>
		<description><![CDATA[As a User Interface Expert first and Programmer second, I put a lot of consideration into how I code. With every step, I do my best to ensure that designers with less programming experience will be able to accomplish what they&#8217;d like. This distinction in programming methods is most clear in how I place dynamic [...]]]></description>
			<content:encoded><![CDATA[<p>As a User Interface Expert first and Programmer second, I put a lot of consideration into how I code. With every step, I do my best to ensure that designers with less programming experience will be able to accomplish what they&#8217;d like. This distinction in programming methods is most clear in how I place dynamic data onto the page.</p>
<p>Whereas many scripts embed the html markup into their javascript, I much prefer to leave it on the page. More specifically, I prefer to leave a <strong><em>model</em></strong> of the html on the page, and to inject the dynamic data using that model. As my example, I&#8217;ll continue <a href="http://www.latentmotion.com/calling-remote-json-files-via-javascript-jquery">yesterday&#8217;s post on a rolling delicious feed</a>.</p>
<p>If you&#8217;d like to skip ahead, you can <a href="http://www.latentmotion.com/downloads/dynamic-cloning.html">view the demo here</a>, or scroll down to view the whole block of code.</p>
<p>But I prefer to break things down first. Let&#8217;s look at my so-called <strong><em>model</em></strong>:</p>
<pre><pre class="brush: xml;">
&lt;div id=&quot;deliciousList&quot;&gt;
    &lt;div id=&quot;deliciousModel&quot; class=&quot;model item&quot;&gt;
        &lt;p&gt;&lt;a class=&quot;url&quot;&gt;&lt;span class=&quot;title&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
        &lt;p&gt;Posted by: &lt;span class=&quot;author&quot;&gt;&lt;/span&gt;&lt;/p&gt;
		&lt;p&gt;Tags: &lt;span class=&quot;tags&quot;&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;
</pre></pre>
<p>Notice that it creates the delicious list, and that inside it is an &#8220;item&#8221;. We&#8217;ll be identifying this model, and duplicating it as many times as we need to. When it&#8217;s duplicated, we&#8217;ll simply find the spans with the appropriate classes, and insert content. It&#8217;s easy and processor efficient, see for yourself:</p>
<pre><pre class="brush: jscript;">
// Clone duplicates the model (with bindings), strips model class/id, gives a unique id, and then adds it before the model
 $(&quot;#deliciousModel&quot;).clone(true).removeAttr(&quot;id&quot;) .removeClass(&quot;model&quot;).attr(&quot;id&quot;, &quot;del&quot; + i).insertBefore(&quot;#deliciousModel&quot;)

 // The finds get each class from within the model and replace it with values from the feed.
 .find(&quot;.url&quot;).attr(&quot;href&quot;, entry.u).end()
 .find(&quot;.author&quot;).html(entry.a).end()
 .find(&quot;.tags&quot;).html(processedTags).end()
 .find(&quot;.title&quot;).html(entry.d);
</pre></pre>
<p>The first line does the cloning, removes the identifying attributes (and class model causes a display:hide;), and inserts the new block.</p>
<p>The subsequent lines insert the appropriate data. Each &#8220;find&#8221; and &#8220;end&#8221; here is really important. By chaining the javascript, we&#8217;re preventing the code from constantly searching the entire document, and we&#8217;re containing the modifications to the model itself.</p>
<p>For the entire block of code, view below:</p>
<pre><pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Delicious Feed&lt;/title&gt;
&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'&gt;&lt;/script&gt;
&lt;script type=&quot;application/javascript&quot;&gt;
    $(document).ready(function(){
// DELICIOUS JSON -- http://feeds.delicious.com/v2/json/tag/hyperstudio
$.getJSON('delicious-json.php', function(data){
$.each(data, function(i, entry) {

tags = entry.t;
tagLength = tags.length;
processedTags = '';

jQuery.each(tags, function(i, val) {
processedTags += ' ' + val;
if (i &lt; tagLength - 1) processedTags += ',';
});

// Clone duplicates the model (with bindings), strips model class/id, gives a unique id, and then adds it before the model
$(&quot;#deliciousModel&quot;).clone(true).removeAttr(&quot;id&quot;) .removeClass(&quot;model&quot;).attr(&quot;id&quot;, &quot;del&quot; + i).insertBefore(&quot;#deliciousModel&quot;)

// The finds get each class from within the model and replace it with values from the feed.
.find(&quot;.url&quot;).attr(&quot;href&quot;, entry.u).end()
.find(&quot;.author&quot;).html(entry.a).end()
.find(&quot;.tags&quot;).html(processedTags).end()
.find(&quot;.title&quot;).html(entry.d);

if ( i == 10 )  return false; // Limit to 10 entries

});
});
    });
&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
html { font-size:10px; font-family:Arial, Helvetica, sans-serif;}
a {color:#066; font-size:12px;}
p {margin:0; padding:0;}
a:hover {color:#099;}
#deliciousList {border:1px solid #333; width:400px; margin:0 auto; padding:0 10px;}
.item {margin:10px 0;}
.clear {clear:both;}
.model {display:none;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;deliciousList&quot;&gt;
    &lt;div id=&quot;deliciousModel&quot; class=&quot;model item&quot;&gt;
        &lt;p&gt;&lt;a class=&quot;url&quot;&gt;&lt;span class=&quot;title&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
        &lt;p&gt;Posted by: &lt;span class=&quot;author&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Tags: &lt;span class=&quot;tags&quot;&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></pre>




	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fusing-jquery-clone-to-add-dynamic-data%252F%26amp%3Btitle%3DUsing%2520jQuery%2520Clone%2520to%2520Add%2520Dynamic%2520Data%26amp%3Bbodytext%3DAs%2520a%2520User%2520Interface%2520Expert%2520first%2520and%2520Programmer%2520second%252C%2520I%2520put%2520a%2520lot%2520of%2520consideration%2520into%2520how%2520I%2520code.%2520With%2520every%2520step%252C%2520I%2520do%2520my%2520best%2520to%2520ensure%2520that%2520designers%2520with%2520less%2520programming%2520experience%2520will%2520be%2520able%2520to%2520accomplish%2520what%2520they%2527d%2520like.%2520This%2520distinctio';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fusing-jquery-clone-to-add-dynamic-data%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fusing-jquery-clone-to-add-dynamic-data%252F%26amp%3Btitle%3DUsing%2520jQuery%2520Clone%2520to%2520Add%2520Dynamic%2520Data%26amp%3Bnotes%3DAs%2520a%2520User%2520Interface%2520Expert%2520first%2520and%2520Programmer%2520second%252C%2520I%2520put%2520a%2520lot%2520of%2520consideration%2520into%2520how%2520I%2520code.%2520With%2520every%2520step%252C%2520I%2520do%2520my%2520best%2520to%2520ensure%2520that%2520designers%2520with%2520less%2520programming%2520experience%2520will%2520be%2520able%2520to%2520accomplish%2520what%2520they%2527d%2520like.%2520This%2520distinctio';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DUsing%2520jQuery%2520Clone%2520to%2520Add%2520Dynamic%2520Data%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fusing-jquery-clone-to-add-dynamic-data%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/using-jquery-clone-to-add-dynamic-data/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
