<?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: Three Quick Ways to Avoid Widows</title>
	<atom:link href="http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/feed" rel="self" type="application/rss+xml" />
	<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows</link>
	<description>Tips, techniques, and tutorials for the jQuery JavaScript library</description>
	<pubDate>Tue, 06 Jan 2009 14:41:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Andrew</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-53522</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Tue, 19 Aug 2008 21:28:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-53522</guid>
		<description>I just noticed that this does not work if the last word is a link. 

Does anyone know how to fix that?</description>
		<content:encoded><![CDATA[<p>I just noticed that this does not work if the last word is a link. </p>
<p>Does anyone know how to fix that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Swedberg</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-53161</link>
		<dc:creator>Karl Swedberg</dc:creator>
		<pubDate>Wed, 13 Aug 2008 14:51:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-53161</guid>
		<description>Hi Andrew,

A quick way to do that with a regular expression would be :
&lt;pre&gt;&lt;code&gt;
$('p.someclass').each(function() {
  var original = $(this).html();
  $(this).html( original.replace(/-/g, '&#8212;') );
});
&lt;/code&gt;&lt;/pre&gt;
Keep in mind, though, that this will mess up IDs or class names that have hyphens in them, if they're in those paragraphs. I don't have time to work out how to avoid that at the moment, but if someone else would like to give it a shot, go for it. :)</description>
		<content:encoded><![CDATA[<p>Hi Andrew,</p>
<p>A quick way to do that with a regular expression would be :</p>
<pre><code>
$('p.someclass').each(function() {
  var original = $(this).html();
  $(this).html( original.replace(/-/g, '&mdash;') );
});
</code></pre>
<p>Keep in mind, though, that this will mess up IDs or class names that have hyphens in them, if they&#8217;re in those paragraphs. I don&#8217;t have time to work out how to avoid that at the moment, but if someone else would like to give it a shot, go for it. <img src='http://www.learningjquery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-53141</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 13 Aug 2008 02:02:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-53141</guid>
		<description>This is a great tip! I am glad that I found this....

What if I wanted to change all hyphens to em dashes? And better yet in a specified paragraph class?

Is this possible? How would you do that?</description>
		<content:encoded><![CDATA[<p>This is a great tip! I am glad that I found this&#8230;.</p>
<p>What if I wanted to change all hyphens to em dashes? And better yet in a specified paragraph class?</p>
<p>Is this possible? How would you do that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MarcusT</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-52396</link>
		<dc:creator>MarcusT</dc:creator>
		<pubDate>Thu, 31 Jul 2008 03:39:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-52396</guid>
		<description>Presenting three different ways to do it is certainly a good way to get people switched on to how best to tackle something, but surely each incurs a different performance hit?

My money's on the second (string-based) method as the best performing approach, but it would be helpful to provide benchmark results in your post so that each solution's performance can be taken into account...

And I wonder what the best way would be of ensuring that if any of the three approaches are accidentally (or intentionally) run multiple times the changes are not reapplied each time, resulting in new lines of 3,4,5,etc words...?</description>
		<content:encoded><![CDATA[<p>Presenting three different ways to do it is certainly a good way to get people switched on to how best to tackle something, but surely each incurs a different performance hit?</p>
<p>My money&#8217;s on the second (string-based) method as the best performing approach, but it would be helpful to provide benchmark results in your post so that each solution&#8217;s performance can be taken into account&#8230;</p>
<p>And I wonder what the best way would be of ensuring that if any of the three approaches are accidentally (or intentionally) run multiple times the changes are not reapplied each time, resulting in new lines of 3,4,5,etc words&#8230;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dylan Hafertepen</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-51793</link>
		<dc:creator>Dylan Hafertepen</dc:creator>
		<pubDate>Tue, 22 Jul 2008 00:59:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-51793</guid>
		<description>Why not use CSS property &lt;code&gt;white-space: nowrap;&lt;/code&gt;?

&lt;pre&gt;&lt;code&gt;
  $('h2').each(function() {
    var h2Contents = $(this).html().split(" ");
    h2Contents[h2Contents.length-2] = '&#60;span style="white-space: nowrap; color: red;"&#62;' + h2Contents[h2Contents.length-2];
    h2Contents[h2Contents.length-1] = h2Contents[h2Contents.length-1] + '&#60;/span&#62;';
    $(this).html(h2Contents.join(' '));
  });
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Why not use CSS property <code>white-space: nowrap;</code>?</p>
<pre><code>
  $('h2').each(function() {
    var h2Contents = $(this).html().split(" ");
    h2Contents[h2Contents.length-2] = '&lt;span style="white-space: nowrap; color: red;"&gt;' + h2Contents[h2Contents.length-2];
    h2Contents[h2Contents.length-1] = h2Contents[h2Contents.length-1] + '&lt;/span&gt;';
    $(this).html(h2Contents.join(' '));
  });
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-51470</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 17 Jul 2008 19:42:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-51470</guid>
		<description>jQuery rocks! Thanks for the great articles!</description>
		<content:encoded><![CDATA[<p>jQuery rocks! Thanks for the great articles!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Swedberg</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-51460</link>
		<dc:creator>Karl Swedberg</dc:creator>
		<pubDate>Thu, 17 Jul 2008 17:53:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-51460</guid>
		<description>Hi Juliano,

Good catch there. Yeah, I didn't account for nested tags in the headings. If you were to do that, you'd need to change &lt;code&gt;h2all = $(this).text();&lt;/code&gt; to &lt;code&gt;h2all = $(this).html();&lt;/code&gt;.</description>
		<content:encoded><![CDATA[<p>Hi Juliano,</p>
<p>Good catch there. Yeah, I didn&#8217;t account for nested tags in the headings. If you were to do that, you&#8217;d need to change <code>h2all = $(this).text();</code> to <code>h2all = $(this).html();</code>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juliano Dasilva</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-51379</link>
		<dc:creator>Juliano Dasilva</dc:creator>
		<pubDate>Wed, 16 Jul 2008 20:04:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-51379</guid>
		<description>Karl, one thing I also noted on this method to avoid widow. If you have an inline element nested to your heading  like this  &lt;pre&gt;&lt;code&gt;&#60;h4&#62;heading goes here &#60;em&#62; July 7th 2008&#60;/em&#62; &#60;/h4&#62; &lt;/code&gt;&lt;/pre&gt; with some style applied to it then the inline element loses its style. I don't know exactly what happens but it bypasses the styles applied to that inline element. I thought I'd point it out since I just ran into this.</description>
		<content:encoded><![CDATA[<p>Karl, one thing I also noted on this method to avoid widow. If you have an inline element nested to your heading  like this
<pre><code>&lt;h4&gt;heading goes here &lt;em&gt; July 7th 2008&lt;/em&gt; &lt;/h4&gt; </code></pre>
<p> with some style applied to it then the inline element loses its style. I don&#8217;t know exactly what happens but it bypasses the styles applied to that inline element. I thought I&#8217;d point it out since I just ran into this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Swedberg</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-50951</link>
		<dc:creator>Karl Swedberg</dc:creator>
		<pubDate>Wed, 09 Jul 2008 23:15:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-50951</guid>
		<description>Thanks, everyone, for the great comments! I think I like Art's suggestion the best for improving the regex: using \S instead of \w. I suppose we could also use [^ ], but \S is more to the point. Must have been the ugly American in me that prevented me from realizing the need to match against extended characters.</description>
		<content:encoded><![CDATA[<p>Thanks, everyone, for the great comments! I think I like Art&#8217;s suggestion the best for improving the regex: using \S instead of \w. I suppose we could also use [^ ], but \S is more to the point. Must have been the ugly American in me that prevented me from realizing the need to match against extended characters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows/comment-page-1#comment-50944</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Wed, 09 Jul 2008 20:16:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows#comment-50944</guid>
		<description>I'd be inclined to do this server-side in my template. I don't think that would be "polluting my markup with something that shouldn't be there." What I wouldn't want to do is change the actual titles in the database, but adding the markup server-side on the fly makes sense to me.</description>
		<content:encoded><![CDATA[<p>I&#8217;d be inclined to do this server-side in my template. I don&#8217;t think that would be &#8220;polluting my markup with something that shouldn&#8217;t be there.&#8221; What I wouldn&#8217;t want to do is change the actual titles in the database, but adding the markup server-side on the fly makes sense to me.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
