<?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: Replacing text in the DOM&#8230; it&#8217;s not that simple!</title>
	<atom:link href="http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 02 Feb 2012 18:03:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: Christopher Blum</title>
		<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/comment-page-1/#comment-31222</link>
		<dc:creator>Christopher Blum</dc:creator>
		<pubDate>Tue, 11 Jan 2011 11:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1601#comment-31222</guid>
		<description>The line:
&lt;pre lang=&quot;javascript&quot;&gt;
textNode.parentNode.insertBefore(textNode, temp.firstChild);
&lt;/pre&gt;

should rather be:
&lt;pre lang=&quot;javascript&quot;&gt;
textNode.parentNode.insertBefore(temp.firstChild, textNode);
&lt;/pre&gt;

Because according to https://developer.mozilla.org/En/DOM/Node.insertBefore the first parameter has to be the node that should be inserted.

Thanks!</description>
		<content:encoded><![CDATA[<p>The line:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">textNode.<span class="me1">parentNode</span>.<span class="me1">insertBefore</span><span class="br0">&#40;</span>textNode<span class="sy0">,</span> temp.<span class="me1">firstChild</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>should rather be:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">textNode.<span class="me1">parentNode</span>.<span class="me1">insertBefore</span><span class="br0">&#40;</span>temp.<span class="me1">firstChild</span><span class="sy0">,</span> textNode<span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>Because according to <a href="https://developer.mozilla.org/En/DOM/Node.insertBefore">https://developer.mozilla.org/En/DOM/Node.insertBefore</a> the first parameter has to be the node that should be inserted.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: "Cowboy" Ben Alman</title>
		<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/comment-page-1/#comment-29498</link>
		<dc:creator>"Cowboy" Ben Alman</dc:creator>
		<pubDate>Thu, 08 Jul 2010 14:36:10 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1601#comment-29498</guid>
		<description>James, great article! I actually created a jQuery plugin last year called &lt;a href=&quot;http://benalman.com/projects/jquery-replacetext-plugin/&quot;&gt;jQuery replaceText&lt;/a&gt; that does pretty much what you&#039;ve covered here, along with an explanation of the general process and caveats, so please check it out when you get a chance!

http://benalman.com/projects/jquery-replacetext-plugin/</description>
		<content:encoded><![CDATA[<p>James, great article! I actually created a jQuery plugin last year called <a href="http://benalman.com/projects/jquery-replacetext-plugin/">jQuery replaceText</a> that does pretty much what you&#8217;ve covered here, along with an explanation of the general process and caveats, so please check it out when you get a chance!</p>
<p><a href="http://benalman.com/projects/jquery-replacetext-plugin/">http://benalman.com/projects/jquery-replacetext-plugin/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/comment-page-1/#comment-29460</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 07 Jul 2010 19:33:33 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1601#comment-29460</guid>
		<description>@Jacob, Neighbouring text nodes isn&#039;t common, but it is something I feel would need to be included in a catch-all solution. The fact that you&#039;re reverting the elements to their original state at all is definitely a good thing! Most of what I covered were edge cases, and I think that you should only consider each one on its own -- IMO it may not be necessary to accommodate all eventualities.

@Rich, I hadn&#039;t considered that this would be a common problem, but you reminded me that there are quite a few WYSIWYG editors that would &lt;em&gt;have to&lt;/em&gt; to build in some kind of mechanism for these edge-cases. CKEditor&#039;s solution is interesting, although I&#039;d probably use just one anchor and nest the &lt;code&gt;em&lt;/code&gt; within it instead of using two separate anchors.

@Gary, I was working on something similar when I encountered all of these problems and decided to write the post -- never ended up publishing the plugin though. Liking your usage of the awesome document fragment btw!

@Can, yup, well, I think each problem has to be considered on its own -- it simply may not be worth covering all bases...</description>
		<content:encoded><![CDATA[<p>@Jacob, Neighbouring text nodes isn&#8217;t common, but it is something I feel would need to be included in a catch-all solution. The fact that you&#8217;re reverting the elements to their original state at all is definitely a good thing! Most of what I covered were edge cases, and I think that you should only consider each one on its own &#8212; IMO it may not be necessary to accommodate all eventualities.</p>
<p>@Rich, I hadn&#8217;t considered that this would be a common problem, but you reminded me that there are quite a few WYSIWYG editors that would <em>have to</em> to build in some kind of mechanism for these edge-cases. CKEditor&#8217;s solution is interesting, although I&#8217;d probably use just one anchor and nest the <code>em</code> within it instead of using two separate anchors.</p>
<p>@Gary, I was working on something similar when I encountered all of these problems and decided to write the post &#8212; never ended up publishing the plugin though. Liking your usage of the awesome document fragment btw!</p>
<p>@Can, yup, well, I think each problem has to be considered on its own &#8212; it simply may not be worth covering all bases&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Can Berkol</title>
		<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/comment-page-1/#comment-29458</link>
		<dc:creator>Can Berkol</dc:creator>
		<pubDate>Wed, 07 Jul 2010 14:29:03 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1601#comment-29458</guid>
		<description>Great article. Harsh problems.. I still like to add that pre-planning may reduce some of these issues - but of course there is also &quot;the client wish&quot; factor; whether the client is your boss, your customer or yourself....</description>
		<content:encoded><![CDATA[<p>Great article. Harsh problems.. I still like to add that pre-planning may reduce some of these issues &#8211; but of course there is also &#8220;the client wish&#8221; factor; whether the client is your boss, your customer or yourself&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Haran</title>
		<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/comment-page-1/#comment-29457</link>
		<dc:creator>Gary Haran</dc:creator>
		<pubDate>Wed, 07 Jul 2010 14:03:32 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1601#comment-29457</guid>
		<description>I&#039;m glad someone discussed this.  I tried solving the same problem in a cross browser way as a jQuery plugin.

You can look at my code here: http://github.com/garyharan/jquery-replace-utilities/</description>
		<content:encoded><![CDATA[<p>I&#8217;m glad someone discussed this.  I tried solving the same problem in a cross browser way as a jQuery plugin.</p>
<p>You can look at my code here: <a href="http://github.com/garyharan/jquery-replace-utilities/">http://github.com/garyharan/jquery-replace-utilities/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich</title>
		<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/comment-page-1/#comment-29456</link>
		<dc:creator>Rich</dc:creator>
		<pubDate>Wed, 07 Jul 2010 09:46:20 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1601#comment-29456</guid>
		<description>Thanks for the article, I found it very interesting as I&#039;ve &lt;a href=&quot;http://github.com/badsyntax/domwalker.js/blob/master/js/domwalker.js&quot;&gt;tried to solve&lt;/a&gt; your last case, alas unsuccessfully. Agreed it&#039;s not possible to solve your last case &#039;unobtrusively&#039;, without a heck-load of DOM scripting. A good working example of the type of logic involved is spell-checking in WYSIWYG editors. TinyMCE spellchecker does not bother (probably for the same reasons you mentioned), but CKEditor manages to solve this, it&#039;s fascinating to see the final markup:
initial html is: &lt;em&gt;number is RF&lt;/em&gt;83297
final html is: &lt;em&gt;number is &lt;/em&gt;&lt;em&gt;&lt;a href=&quot;/order/RF83297&quot;&gt;RF&lt;/a&gt;&lt;/em&gt;&lt;a href=&quot;/order/RF83297&quot;&gt;83297&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for the article, I found it very interesting as I&#8217;ve <a href="http://github.com/badsyntax/domwalker.js/blob/master/js/domwalker.js">tried to solve</a> your last case, alas unsuccessfully. Agreed it&#8217;s not possible to solve your last case &#8216;unobtrusively&#8217;, without a heck-load of DOM scripting. A good working example of the type of logic involved is spell-checking in WYSIWYG editors. TinyMCE spellchecker does not bother (probably for the same reasons you mentioned), but CKEditor manages to solve this, it&#8217;s fascinating to see the final markup:<br />
initial html is: &lt;em&gt;number is RF&lt;/em&gt;83297<br />
final html is: &lt;em&gt;number is &lt;/em&gt;&lt;em&gt;&lt;a href=&quot;/order/RF83297&quot;&gt;RF&lt;/a&gt;&lt;/em&gt;&lt;a href=&quot;/order/RF83297&quot;&gt;83297&lt;/a&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham</title>
		<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/comment-page-1/#comment-29455</link>
		<dc:creator>Graham</dc:creator>
		<pubDate>Wed, 07 Jul 2010 09:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1601#comment-29455</guid>
		<description>A nice warning to show that libraries can&#039;t cover all the bases.</description>
		<content:encoded><![CDATA[<p>A nice warning to show that libraries can&#8217;t cover all the bases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Waller</title>
		<link>http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/comment-page-1/#comment-29454</link>
		<dc:creator>Jacob Waller</dc:creator>
		<pubDate>Wed, 07 Jul 2010 08:33:54 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1601#comment-29454</guid>
		<description>Interesting read, James!
I created a search-in-page search bar bookmarklet for iOS (yeah, I know...) devices (and potentially Android) the other day, and ran in to many of the problems you describe. I did come up with a similar solution, though not as well-reasoned as yours. If you&#039;d be interested, it&#039;s available here: http://github.com/krawaller/prettySearch.js as an early release. Please feel free to bash it - I could definitely use your help :)

I saw that manually creating text nodes may lead to neighbouring text nodes, but when does this happen in the wild? Also: currently, I normalize the elements only when I revert the search - how bad is this?</description>
		<content:encoded><![CDATA[<p>Interesting read, James!<br />
I created a search-in-page search bar bookmarklet for iOS (yeah, I know&#8230;) devices (and potentially Android) the other day, and ran in to many of the problems you describe. I did come up with a similar solution, though not as well-reasoned as yours. If you&#8217;d be interested, it&#8217;s available here: <a href="http://github.com/krawaller/prettySearch.js">http://github.com/krawaller/prettySearch.js</a> as an early release. Please feel free to bash it &#8211; I could definitely use your help <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I saw that manually creating text nodes may lead to neighbouring text nodes, but when does this happen in the wild? Also: currently, I normalize the elements only when I revert the search &#8211; how bad is this?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

