<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://www.netlobo.com/commentsrss.php?aid=86" rel="self" type="application/rss+xml" />
		<title>Comments on: Javascript DOM insertAfter function</title>
		<description>The Javascript DOM functions do not include an insertAfter function. In this article we show you how to create your own elegant and simple insertAfter function</description>
		<link>http://www.netlobo.com/comments/javascript-insertafter</link>
		<language>en-us</language>
		<copyright>Copyright 2010, Netlobo.com</copyright>
		<lastBuildDate>Fri, 21 Aug 2009 20:29:52 GMT</lastBuildDate>
		<generator>Netlobo In-house RSS v1.4</generator>
		<item>
			<title>James</title>
			<description>Works, unless the element is the last child, i.e. &amp;lt;td&amp;gt;&amp;lt;hr /&amp;gt;&amp;lt;/td&amp;gt;.  You should add a condition that checks if it is the last child, and if it is, simply use appendChild();&lt;br /&gt;
&lt;br /&gt;
function insertAfter(newElem,elem)&lt;br /&gt;
{&lt;br /&gt;
    if(elem.nextSibling) elem.parentNode.appendChild(newElem);&lt;br /&gt;
else elem.parentNode.insertBefore(newElem,elem.nextsibling);</description>
			<link>http://www.netlobo.com/comments/javascript-insertafter#comment-468</link>
			<guid>http://www.netlobo.com/comments/javascript-insertafter#comment-468</guid>
			<pubDate>Fri, 21 Aug 2009 20:11:04 GMT</pubDate>
		</item>
		<item>
			<title>RobS</title>
			<description>Nutria, it is working for me in IE.  I noticed you spelled Sibling with 2 B's.   Maybe that is why it was coming up as &amp;quot;undefined&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Anyway, this solution was great, saved my coding project from turning into something ugly.  Very elegant and simple--awesomeness.</description>
			<link>http://www.netlobo.com/comments/javascript-insertafter#comment-412</link>
			<guid>http://www.netlobo.com/comments/javascript-insertafter#comment-412</guid>
			<pubDate>Thu, 26 Mar 2009 03:14:54 GMT</pubDate>
		</item>
		<item>
			<title>nutria</title>
			<description>Theres no wcs here. I was trying the code a while ago and managed to fire an error on IE. The problem happens when the referenceNode.nextSibbling is undefined.&lt;br /&gt;
&lt;br /&gt;
In the original example there was a text node (the line change in the code) that was acting as a nextSibbling for the supoussed to be last element. When deleting the line change IE7 stopped working because the node.insertBefore functions does not expect a undefined value as second parameter.&lt;br /&gt;
&lt;br /&gt;
So for IE to work is necesary to map the undefined value to null.&lt;br /&gt;
&lt;br /&gt;
Now without further ado... the function... this is working well for me.&lt;br /&gt;
&lt;br /&gt;
var undefined;&lt;br /&gt;
function insertAfter (node, newNode){&lt;br /&gt;
	var parent = node.parentNode;&lt;br /&gt;
	var next = node.nextSibbling;&lt;br /&gt;
	//following: the IE fix&lt;br /&gt;
	if (next==undefined) next=null;&lt;br /&gt;
	parent.insertBefore(newNode,next);&lt;br /&gt;
}</description>
			<link>http://www.netlobo.com/comments/javascript-insertafter#comment-319</link>
			<guid>http://www.netlobo.com/comments/javascript-insertafter#comment-319</guid>
			<pubDate>Fri, 29 Aug 2008 20:02:12 GMT</pubDate>
		</item>
		<item>
			<title>JS</title>
			<description>Worst Case Scenario: If you're afraid that insertBefore won't work, just make the additional mods:&lt;br /&gt;
&lt;pre&gt;
// This function inserts newNode after referenceNode
function insertAfter( referenceNode, newNode )
{
    if (referenceNode.nextSibling) {
        referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
    }
    else {
        referenceNode.parentNode.appendChild( newNode);
    }
}
&lt;/pre&gt;</description>
			<link>http://www.netlobo.com/comments/javascript-insertafter#comment-275</link>
			<guid>http://www.netlobo.com/comments/javascript-insertafter#comment-275</guid>
			<pubDate>Thu, 10 Jul 2008 08:36:33 GMT</pubDate>
		</item>
		<item>
			<title>ANON</title>
			<description>I just tried this to add tags to the very bottom of documents in both IE7 and FF2 - worked like a charm!!&lt;br /&gt;
Thanks very much</description>
			<link>http://www.netlobo.com/comments/javascript-insertafter#comment-270</link>
			<guid>http://www.netlobo.com/comments/javascript-insertafter#comment-270</guid>
			<pubDate>Thu, 03 Jul 2008 07:32:55 GMT</pubDate>
		</item>
		<item>
			<title>ANON</title>
			<description>I just tried it in IE7 and FF2 - worked like a charm!</description>
			<link>http://www.netlobo.com/comments/javascript-insertafter#comment-269</link>
			<guid>http://www.netlobo.com/comments/javascript-insertafter#comment-269</guid>
			<pubDate>Thu, 03 Jul 2008 06:48:39 GMT</pubDate>
		</item>
		<item>
			<title>lobo235</title>
			<description>odavis4,&lt;br /&gt;
&lt;br /&gt;
You may think that it doesn't work but did you actually try it? I have tried it in Opera, Safari, Firefox and IE and it works in all of the browsers without checking if the element is the parent's last child, etc.&lt;br /&gt;
&lt;br /&gt;
It would be wise to try something yourself before labeling it as 'hilariously trite, poor javascript' when it is in fact simple and efficient javascript.</description>
			<link>http://www.netlobo.com/comments/javascript-insertafter#comment-264</link>
			<guid>http://www.netlobo.com/comments/javascript-insertafter#comment-264</guid>
			<pubDate>Fri, 27 Jun 2008 16:15:05 GMT</pubDate>
		</item>
		<item>
			<title>odavis4</title>
			<description>This won't work of course if the element you're trying to insert after is the last element in the reference element's parent.  Besides, this is hilariously trite, poor javascript (just Google 'javascript insertAfter' to get a grasp of the uninformed horror).  Try checking whether the reference element is equal to the parent's last child and appending the new element if so, doing what everybody else seems to strain themselves doing only otherwise.</description>
			<link>http://www.netlobo.com/comments/javascript-insertafter#comment-252</link>
			<guid>http://www.netlobo.com/comments/javascript-insertafter#comment-252</guid>
			<pubDate>Fri, 23 May 2008 02:20:56 GMT</pubDate>
		</item>
	</channel>
</rss>

<!-- pageGen: 0.0021 secs -->
<!-- memcache hits: 2 memcache misses: 0 -->