<?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>Travis, Travaganza &#187; HTML styling</title>
	<atom:link href="http://www.travislin.com/tag/html-styling/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.travislin.com</link>
	<description>Web Design, Technologies and Fancy photos of what I see.</description>
	<lastBuildDate>Wed, 25 Jan 2012 05:44:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Add external link icon after all external links using jQuery</title>
		<link>http://www.travislin.com/2009/05/add-external-link-icon-after-all-external-links-using-jquery/</link>
		<comments>http://www.travislin.com/2009/05/add-external-link-icon-after-all-external-links-using-jquery/#comments</comments>
		<pubDate>Sat, 09 May 2009 07:42:54 +0000</pubDate>
		<dc:creator>Travis</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML styling]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.travislin.com/?p=31</guid>
		<description><![CDATA[Here is a very simple tutorial on how you can automatically insert an icon image after external (also known as off-site) links by using jQuery javacript framework. For those who are not familiar with jQuery: jQuery is a lightweight JavaScript &#8230; <a href="http://www.travislin.com/2009/05/add-external-link-icon-after-all-external-links-using-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-medium wp-image-38" title="p03-ss02" src="http://www.travislin.com/wp-content/uploads/2009/05/p03-ss02-300x194.gif" alt="p03-ss02" width="300" height="194" /></p>
<p>Here is a very simple tutorial on how you can automatically insert an icon image after external (also known as off-site) links by using <a class="external_icon" title="jQuery Framework Homepage" href="http://jquery.com/" target="_blank">jQuery javacript framework</a>.<span id="more-31"></span></p>
<p>For those who are not familiar with jQuery:</p>
<blockquote><p>jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML. It was released January 2006 at BarCamp NYC by John Resig.</p></blockquote>
<p style="text-align: center;"><em>Description of jQuery quoted from <a class="external_icon" title="Wikipedia page: jQuery" href="http://en.wikipedia.org/wiki/JQuery" target="_blank">Wikipedia</a>.</em></p>
<p>Reason I choose to go with javscript implementation instead of pure CSS is so that you do not have go through your entire blog to specified every link that you want to be marked as external link &#8211; leave this job to computer!</p>
<p>(Note: You also able to achieve this automatically using <a class="external_icon" title="Programmabilities: External Link Icons with CSS Selectors" href="http://programmabilities.com/xml/?id=30" target="_blank">CSS3 selector</a>, however CSS3 implementation is still in draft and is<a class="external_icon" title="Wikipedia: Comparison of layout engines" href="http://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28CSS%29" target="_blank"> still not fully supported by browsers</a>.)</p>
<p>I will be using jQuery 1.3.2, the latest version to-date. Add the follwing javscript to your page:</p>
<pre class="brush:php">
<script language="javascript" type="text/javascript">
<!--	
	(function($)
	{
		$(document).ready(function()
		{
			/* Add class to all anchor targeting a blank page */
			$("a[target=''_blank'']").addClass("external_icon");
		});
	}(jQuery));
//-->
</script>
</pre>
<p>This javascript selects anchors that has target=”_blank” attributes on them and gives those anchors a new class “external_icon”.</p>
<p>Next step would be applying style to those anchors with “external_icon” class:</p>
<pre class="brush:css">
a.external_icon {
	background: url(images/external-link.gif) no-repeat 100% 50%;
	padding-right: 12px;
}
</pre>
<p>That&#8217;s it! 2 steps, very simple as promised. However couple of things you may want to watch out for. Below is couple of tweaks you may consider adding.</p>
<h3>Image Exception</h3>
<p>Having a small external link icon next to an image looks worse than without it, you may examption to anchored images by:</p>
<pre class="brush:php">
<script language="javascript" type="text/javascript">
<!--
	(function($)
	{
		$(document).ready(function()
		{
			/* Add class to all anchor targeting a blank page */
			$("a[target=''_blank'']").addClass("external_icon");

			/* Remove class if anchor is on an image */
			$("a[target=''_blank''] img").parent().removeClass("external_icon");
		});
	}(jQuery));
//-->
</script>
</pre>
<h3>Specified Anchor Exclusion</h3>
<p>If there are certain links in the post that you feel like not having an external link icon and want to exclude them from applying the style, then specified a &#8220;no_external_icon&#8221; class to those links and have your javascript code as follow:</p>
<pre class="brush:php">
<script language="javascript" type="text/javascript">
<!--
	(function($)
	{
		$(document).ready(function()
		{
			/* Add class to all anchor targeting a blank page */
			$("a[target=''_blank'']").addClass("external_icon");

			/* Remove class if anchor is on an image */
			$("a[target=''_blank''] img").parent().removeClass("external_icon");

			/* Remove class if anchor is specified not to have external icon */
			$("a[target=''_blank''].no_external_icon").removeClass("external_icon");
		});
	}(jQuery));
//-->
</script>
</pre>
<p>Now you have it! Try the code out yourself!</p>
<p><span style="color: #ff0000;"><em><strong>Edit on 2009-05-12:</strong></em></span></p>
<p>Thanks to <a title="GunnerPress Homepage" rel="external nofollow" href="http://www.travislin.com/2009/05/add-external-link-icon-after-all-external-links-using-jquery/#comment-2">J Mehmett</a> for pointing out that <code>target="_blank"</code> is invalid in XHTML 1.0 Strict (however remain valid in XHTML 1.0 Transitional and HTML 4.01 Transitional as <code>target</code> attribute is not yet deprecated).</p>
<p>In that case:</p>
<h3>Specified Relationship Inclusion</h3>
<p>Advanced web developers has slowly stop the usage of <code>target</code> and using <code>rel</code> attribute instead.</p>
<pre class="brush:php">
<script language="javascript" type="text/javascript">
<!--
	(function($)
	{
		$(document).ready(function()
		{
			/* Add class to all anchor targeting a blank page */
			$("a[rel=''external'']").addClass("external_icon");

			/* Open external links as a new tab/page */
			$("a[rel=''external'']").click(function(){
				this.target = "_blank";
			});
		});
	}(jQuery));
//-->
</script>
</pre>
<p>Without too much trouble, we can achieve the same result by using above!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.travislin.com/2009/05/add-external-link-icon-after-all-external-links-using-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

