<?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>dtsn &#187; Prototype</title>
	<atom:link href="http://dtsn.co.uk/category/javascript/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://dtsn.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 17 Aug 2010 13:18:57 +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>Bouncing JavaScript Tutorial</title>
		<link>http://dtsn.co.uk/2010/01/07/bouncing-javascript-tutorial/</link>
		<comments>http://dtsn.co.uk/2010/01/07/bouncing-javascript-tutorial/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 11:00:38 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Scriptaculous]]></category>
		<category><![CDATA[Bounce]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=692</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p><strong>Original Source</strong>: http://giancarlo.dimassa.net</p>
<p>There have been&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2010%2F01%2F07%2Fbouncing-javascript-tutorial%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=Bounce,JavaScript,Prototype,Scriptaculous&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>Original Source</strong>: <a href="http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/">http://giancarlo.dimassa.net</a></p>
<p>There have been many examples of bouncing effects in <a href="http://script.aculo.us/">scriptaculous</a> but this one has to be one of the most realistic. It uses the equations developed by <a href="http://www.robertpenner.com/">Robert Penner</a> to accurately represent a bounce, and it does look cool.</p>
<h2>What you need</h2>
<p>As with most of my tutorials this is based on <a href="http://script.aculo.us/">scriptaculous</a> and <a href="http://www.prototypejs.org/">prototype</a>, but the equations could easily be porter to other animation frameworks.</p>
<h2>The code</h2>
<p>This is really simple, basically what we are going to be doing is to add a new transitional effect to scriptaculous. To do this we just extend the Effect class.</p>
<p><strong>Add this to your own JavaScript file instead of scriptaculous, so you don’t loose it when you update.</strong></p>
<pre class="js" name="code">/*Based on Easing Equations v2.0
(c) 2003 Robert Penner, all rights reserved.
This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html

Adapted for Scriptaculous by Ken Snyder (kendsnyder ~at~ gmail ~dot~ com) June 2006
*/

Effect.Transitions.Bounce = function (pos) {
    if (pos &lt; 0.36363636363636365) {
        return 7.5625 * pos * pos;
    } else if (pos &lt; 0.7272727272727273) {
        return 7.5625 * (pos -= 0.5454545454545454) * pos + 0.75;
    } else if (pos &lt; 0.9090909090909091) {
        return 7.5625 * (pos -= 0.8181818181818182) * pos + 0.9375;
    } else {
        return 7.5625 * (pos -= 0.9545454545454546) * pos + 0.984375;
    }
}</pre>
<h2>Use it</h2>
<p>You can use this effect as a transition type with lots of effects.</p>
<pre>new Effect.BlindDown(div, {
    duration: 0.5,
    transition: Effect.Transitions.Bounce
});</pre>
<p>Check out <a href="http://giancarlo.dimassa.net/2007/07/11/elastic-and-bouncing-transitions-in-scriptaculous/">Ken Snyder’s</a> blog for more transitional effects.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2010/01/07/bouncing-javascript-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Check/Uncheck Checkboxes</title>
		<link>http://dtsn.co.uk/2009/12/10/javascript-checkuncheck-checkboxes/</link>
		<comments>http://dtsn.co.uk/2009/12/10/javascript-checkuncheck-checkboxes/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 12:00:00 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Check All]]></category>
		<category><![CDATA[Checkbox]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Uncheck All]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=685</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>This tutorial is a really simple&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F12%2F10%2Fjavascript-checkuncheck-checkboxes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=Check+All,Checkbox,Form,HTML,JavaScript,Prototype,Uncheck+All&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This tutorial is a really simple one and is only a one liner in prototype (slight more in regular JavaScript). It will check all the checkboxes on a page, and a function to uncheck all checkboxes quite handy really especially if you are dealing with long lists.</p>
<h2>Check All</h2>
<pre class="js" name="code">$$('input[type=&quot;checkbox&quot;]').invoke('writeAttribute', 'checked', 'checked');</pre>
<p>What we are doing here is selecting all the inputs of type checkbox and enumerating over them writing a check attribute to each one.</p>
<h2>Uncheck All</h2>
<pre class="js" name="code">$$('input[type=&quot;checkbox&quot;]').invoke('removeAttribute', 'checked');</pre>
<p>As you can guess this just the opposite way round.</p>
<h2>JavaScript</h2>
<p>You can do the same basic principle without a framework:</p>
<pre class="js" name="code">// check all
var inputs = document.getElementsByTagName('input');
for (var i = 0; i &lt; inputs.length; i++) {
	if (inputs[i].type == 'checkbox') {
		inputs[i].checked = true;
	}
}

// uncheck all
var inputs = document.getElementsByTagName('input');
for (var i = 0; i &lt; inputs.length; i++) {
	if (inputs[i].type == 'checkbox') {
		inputs[i].checked = false
	}
}</pre>
<p>That&#8217;s it there isn&#8217;t really much to it, but I thought it was worth sharing.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/12/10/javascript-checkuncheck-checkboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Weather</title>
		<link>http://dtsn.co.uk/2009/11/26/javascript-weather/</link>
		<comments>http://dtsn.co.uk/2009/11/26/javascript-weather/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 16:08:33 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Pipes]]></category>
		<category><![CDATA[Weather]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=639</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>Here’s a crazy idea, what would&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F11%2F26%2Fjavascript-weather%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=JavaScript,JSON,Pipes,Weather,Yahoo&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Here’s a crazy idea, what would you do if you wanted to change the background picture of your website so it matches the weather. Luckily Its really easy, and I figured out all the hard bits for you.</p>
<p><em>UPDATE &#8211; Chris Heilmann over at the </em><a href="http://developer.yahoo.net/blog/archives/2009/12/extending_the_weather_api_with_yql.html"><em>Yahoo! Developer Network Blog</em></a><em> has made this even simpler through the use of YQL.</em></p>
<h2>The Data</h2>
<p>First of all we need a data source which will provide the weather for a particular location, we can grab this from the <a href="http://developer.yahoo.com/weather/">Yahoo Weather API</a>. Using the code UKXX0117 which is for Reading, UK I can create the an RSS feed which you can see here <a title="http://weather.yahooapis.com/forecastrss?p=UKXX0117&amp;u=c" href="http://weather.yahooapis.com/forecastrss?p=UKXX0117&amp;u=c">http://weather.yahooapis.com/forecastrss?p=UKXX0117&amp;u=c</a>. Great but how can we process this RSS feed? That’s where <a href="http://pipes.yahoo.com">Yahoo Pipes</a> comes in, we can take in the RSS feed extract the data we need (item.yweather.condition) and export it as JSON.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://dtsn.co.uk/wp-uploads/2009/11/image3.png" width="480" height="269" /></p>
<p>Now we can access the JSON data for the weather in Reading <a href="http://pipes.yahoo.com/pipes/pipe.run?_id=b13966505cb6b00dd1d18ec4aafc14b4&amp;_render=json">here</a>.</p>
<h2>JavaScript</h2>
<p>The JavaScript cannot directly call the JSON script via AJAX due to cross site scripting limitations imposed by the browser. This is where JSONP comes in, JSONP is a way to retrieve data from external domains through wrapping the JSON in a function, you can read more on JSONP at <a href="http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/">from__future__import</a>. Yahoo Pipes fully supports the JSONP format using the parameter callback, therefore in our webpage we load up the following.</p>
<pre class="html" name="code">&lt;script type=&quot;text/javascript&quot; src=&quot;http://pipes.yahoo.com/pipes/pipe.run?_id=b13966505cb6b00dd1d18ec4aafc14b4&amp;_render=json&amp;_callback=weather&quot;&gt;&lt;/script&gt;</pre>
<p>This will call the function weather passing through a weather status code as the parameter.</p>
<p>That is really it, you can do whatever you want with the data, here’s a quick example of how I would use it.</p>
<pre class="js" name="code">function weather(data) {
        var code = data.value.items[0].content;
	switch(code) {
		case '32': $(document.body).addClassName('sunny');
		break;
	}
}</pre>
<h2>Example</h2>
<p><script type="text/javascript" src="http://pipes.yahoo.com/pipes/pipe.run?_id=b13966505cb6b00dd1d18ec4aafc14b4&amp;_render=json&amp;_callback=weather"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/11/26/javascript-weather/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TweetTabs, A Story</title>
		<link>http://dtsn.co.uk/2009/06/17/tweettabs-a-story/</link>
		<comments>http://dtsn.co.uk/2009/06/17/tweettabs-a-story/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 22:09:51 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[TweetTabs]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=574</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>For everyone who follows me on&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2009%2F06%2F17%2Ftweettabs-a-story%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>For everyone who follows me on twitter or knows me personally would know that yesterday I launched something that i have been working on for a very long time. <a href="http://tweettabs.com">TweetTabs</a> is a way of tracking real-time twitter trends and searches, and has been my little project since i first started on it back in Easter. The idea came from the lack on online real-time ways to interface with twitter, the premise is simple, i wanted an easy way to search for things in twitter which constantly updated, so TweetTabs was born. </p>
<p>The initial application was written in about 2 hours entirely in JavaScript, it later went through a number of huge revisions especially over the Easter weekend. It gained quite a lot of features, and then lost them. I wrote an entire OAuth module in JavaScript, then realised that you can’t authenticate headers. The project was basically done apart from one of the most complicated features. Then my life changed, I broke up with my long term girlfriend, of 5 years, and had to move back home with my parents. Even though this didn’t dent my enthusiasm for the project it definitely affected the timescales.</p>
<h2>How it works</h2>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dtsn.co.uk/wp-content/uploads/2009/06/image-thumb.png" width="480" height="310" /></p>
<p>TweetTabs is a very simple idea, but it takes a very long time to solve the problems it presents. The entire application is written in JavaScript, this gets around the notion of having a API limit for your twitter searches, you are now only limited by your I.P. address, which has a much higher (not declared) limit. For every tab TweetTab hits twitter to fetch the data, this is controlled by our adaptive pollrate. Put simply this means that each tab can work out the optimum time to fetch more data from twitter. We try and limit the number of times TweetTabs hits twitter in the hour, mostly so that you don&#8217;t reach your API limit (it is possible, and I did it a lot in testing), and we don&#8217;t overload twitter.</p>
<p> <object width="480" height="360"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5208057&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5208057&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="480" height="360"></embed></object>
<p><a href="http://vimeo.com/5208057">TweetTabs Screencast</a> from <a href="http://vimeo.com/user546294">Daniel Saxil-Nielsen</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<h2>Coverage</h2>
<p>So now TweetTabs has been launched and has had loads of positive feedback and has been covered on loads of huge sites:</p>
<ul>
<li><a title="http://www.techcrunch.com/2009/06/16/tweettabs-is-an-awesome-way-to-search-twitter/" href="http://www.techcrunch.com/2009/06/16/tweettabs-is-an-awesome-way-to-search-twitter/">http://www.techcrunch.com/2009/06/16/tweettabs-is-an-awesome-way-to-search-twitter/</a> </li>
<li><a title="http://mashable.com/2009/06/16/tweettabs/" href="http://mashable.com/2009/06/16/tweettabs/">http://mashable.com/2009/06/16/tweettabs/</a> </li>
</ul>
<h2>Dedications</h2>
<p>I don’t know whether this is normally done for releasing products, but I feel it is appropriate, I would like to mention everyone who helped with the process along the way. Starting firstly with <a href="http://twitter.com/nickhalstead" target="_blank">@nickhalstead</a>, who supported me the whole way (and sorry it took so long). <a href="http://twitter.com/nicktelford" target="_blank">@nicktelford</a> who was there to bounce ideas of and to find lots of bugs just before we were about the launch. <a href="http://twitter.com/alexforrow" target="_blank">@alexforrow</a> for writing a really good deployment script, which merges all the files and obfuscates them. All the great people that tested it along the way: <a href="http://twitter.com/chris_alexander" target="_blank">@chris_alexander</a>, <a href="http://twitter.com/craigyd" target="_blank">@craigyd</a>, <a href="http://twitter.com/amykate" target="_blank">@amykate</a> and <a href="http://twitter.com/girlygeekdom" target="_blank">@girlygeekdom</a> (who is probably the one who answers <a href="http://twitter.com/tweettabs" target="_blank">@tweettabs</a> questions online). </p>
<p>TweetTabs is built using <a href="http://prototypejs.org" target="_blank">Prototype</a> and the JavaScript framework, and is powered by <a href="http://tweetmeme.com">TweetMeme</a>, and <a href="http://twitter.com" target="_blank">Twitter</a>.     </p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2009/06/17/tweettabs-a-story/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Halloween Effects</title>
		<link>http://dtsn.co.uk/2008/10/26/javascript-halloween-effects/</link>
		<comments>http://dtsn.co.uk/2008/10/26/javascript-halloween-effects/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 22:40:00 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[CSS/HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Scriptaculous]]></category>

		<guid isPermaLink="false">http://dtsn.co.uk/?p=527</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>Halloween is just around the corner&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2008%2F10%2F26%2Fjavascript-halloween-effects%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Halloween is just around the corner and what better to jazz your blog up than with some Halloween related JavaScript. This tutorial will focus on making images appear and disappear on the background of your blog.</p>
<p>For this example I will be using a ghost which will appear every two seconds in a random location and disappear again. You can preview what this will look like by clicking the button below (<em>only viewable in a web browser</em>).</p>
<p>You can download the source files for this tutorial below as well as the ghost AI file.</p>
<input type="button" onclick="new Ghost();" value="Try Me" />
<p><a href="/wp-content/uploads/2008/10/Ghost.zip">Source Files</a></p>
<p>For this tutorial we are going to be using <a onclick="javascript:pageTracker._trackPageview(&#39;/outgoing/script.aculo.us/&#39;);" href="http://script.aculo.us/">Script.aculo.us</a> effects library with the <a onclick="javascript:pageTracker._trackPageview(&#39;/outgoing/ww.prototypejs.org&#39;);" href="http://ww.prototypejs.org">Prototype</a> core framework.</p>
<pre class="javascript" name="code">var Ghost = Class.create({
	initialize: function() {
	}
});</pre>
<p>First of all we need to create our Class, which is called <em>Ghost</em>. Inside the class <em>Ghost</em> we have added our initialize function. The initialize function will be called when we create a new instance of the class. Therefore we need to put in all our setup code:</p>
<pre class="javascript" name="code"> // create the element
this.ghost = new Element('div', {'class' : 'ghost'});
// hide the element
this.ghost.hide();
// add the element to the body
$(document.body).insert({top: this.ghost});
// get the size of the document
this.size = document.viewport.getDimensions();
// set up the timer
new PeriodicalExecuter(this.show.bindAsEventListener(this), 2);</pre>
<p>In this segment we create our hidden ghost element. We then store the size of the document, and load up our periodical executer to call <em>this.show</em>. The second parameter in the Periodical Executer is the time between calls, we are calling the show function once every 2 seconds.</p>
<pre class="javascript" name="code">show: function() {
	// randomly set where the ghost is going
	var x = Math.floor(Math.random()*(this.size['width']-200));
	var y = Math.floor(Math.random()*(this.size['height']-200));
	// set the style
	this.ghost.setStyle({
		'left': x + 'px',
		'top': y + 'px'
	});

	// show the object
	this.ghost.appear({
		afterFinish: function() {
			this.ghost.fade();
		}.bind(this)
	});
}</pre>
<p>The show function needs to be added to the <em>Ghost</em> class. The show function first calculates where we want our ghost to appear, so we work out random x and y co-ordinates using the document sizes we gathered in our initialize function. We then position the element and call the <a onclick="javascript:pageTracker._trackPageview(&#39;/outgoing/script.aculo.us/&#39;);" href="http://script.aculo.us/">Script.aculo.us</a> appear effect which will slowly fade in the image. After the appear effect has finish we want to hide the ghost so we call fade.</p>
<p>Ok, now we have all the code complete we need to call the class. We can do this in a number of ways, you could bind the event to a button:</p>
<pre class="html" name="code">
<div onclick="new Ghost()">BOO</div>
</pre>
<p>Or you can bind it into your document load function, which means it will start when the page loads:</p>
<pre class="javascript" name="code">document.observe("dom:loaded", function() {
	new Ghost();
});</pre>
<h3>CSS</h3>
<p>The CSS is a really simple one line.</p>
<pre class="css" name="code">.ghost { width: 100px; height: 100px; position: absolute; background: url('yourimage.png') no-repeat; }</pre>
<p>This tutorial is just a brief outline with what you can do with JavaScript this Halloween. If you have any other ideas you would like me to implement, please tell me in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2008/10/26/javascript-halloween-effects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Prototype Element.Insert</title>
		<link>http://dtsn.co.uk/2008/05/01/elementinsert-javascript/</link>
		<comments>http://dtsn.co.uk/2008/05/01/elementinsert-javascript/#comments</comments>
		<pubDate>Fri, 02 May 2008 05:13:47 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[Element.Insert]]></category>

		<guid isPermaLink="false">http://www.dtsn.co.uk/?p=191</guid>
		<description><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<br />
				<br />
			
		</div>
<p>Prototype has a very useful function&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 3px 0px 0px 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdtsn.co.uk%2F2008%2F05%2F01%2Felementinsert-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=dtsn&amp;style=normal&amp;service=is.gd&amp;hashtags=DOM,Element.Insert,JavaScript,Prototype&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.prototypejs.org">Prototype</a> has a very useful function which is not well documented, <a href="http://www.prototypejs.org/api/element/insert">Element.inset</a>. Element.insert is a very powerful prototype function which lets you insert a element in one of 4 positions, <em>before, after, top, bottom</em> of an element.</p>
<p>If we wanted to insert an element after a element we would use this code:</p>
<p>[code="javascript"]<br />
Element.insert(first-element, {top: content});<br />
[/code]</p>
<p>Expanding this further:</p>
<p>[code="javascript"]<br />
// lets create our element<br />
var dummy = new Element('div').update('Hello World');<br />
// add the element<br />
Element.insert($('hook'), {after: dummy});<br />
[/code]<br />
<em>Where hook is the element we want before our created element</em></p>
<p>This code will add our Hello World text after the div with the id of hook.</p>
]]></content:encoded>
			<wfw:commentRss>http://dtsn.co.uk/2008/05/01/elementinsert-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

