<?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>The Accidental Developer &#187; DOM</title>
	<atom:link href="http://osric.com/chris/accidental-developer/tag/dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://osric.com/chris/accidental-developer</link>
	<description>What if Gregor Samsa awoke a computer programmer?</description>
	<lastBuildDate>Mon, 30 Apr 2012 21:16:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Javascript insertAfter()</title>
		<link>http://osric.com/chris/accidental-developer/2009/08/javascript-insertafter/</link>
		<comments>http://osric.com/chris/accidental-developer/2009/08/javascript-insertafter/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 23:12:47 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[insertAfter]]></category>
		<category><![CDATA[insertBefore]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=217</guid>
		<description><![CDATA[Although Javascript doesn't contain a DOM function for Node.insertAfter(), you can easily emulate it using Node.insertBefore -- and even call it via Node.insertAfter()]]></description>
			<content:encoded><![CDATA[<p>There is no <em>Node.insertAfter()</em> DOM function in Javascript, but it is clearly something that developers would like.</p>
<p>As the <a href="https://developer.mozilla.org/en/Gecko_DOM_Reference">Gecko DOM Reference</a> for <a href="https://developer.mozilla.org/En/DOM/Node.insertBefore">Node.insertBefore()</a> points out, this can easily be achieved with<br />
<code>parentDiv.insertBefore(nodeToInsert, nodeToInsertAfter.nextSibling);</code></p>
<p>If <em>nodeToInsertAfter</em> doesn&#8217;t have a next sibling, a NULL value will be returned and <em>nodeToInsert</em> will be inserted as the last child of <em>parentDiv</em>.</p>
<p>If you find it frustrating to type <em>insertBefore</em> when you want to <em>insertAfter</em>, that&#8217;s OK: you can add that function to the Object object:<br />
<code>Object.prototype.insertAfter = function (newNode) { this.parentNode.insertBefore(newNode, this.nextSibling); }</code></p>
<p>Now you can type:<br />
<code>nodeToInsertAfter.insertAfter(nodeToInsert)</code></p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2009/08/javascript-insertafter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

