<?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>{ Code: Impossible } &#187; jquery-extensions</title>
	<atom:link href="http://codeimpossible.com/tag/jquery-extensions/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeimpossible.com</link>
	<description>this = HowI.Roll();</description>
	<lastBuildDate>Thu, 09 Sep 2010 15:45:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using jQuery on an Iframe</title>
		<link>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/</link>
		<comments>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 01:10:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery-extensions]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=803</guid>
		<description><![CDATA[The other day I had to alter the stylesheets in a child IFrame when a user selected an item from a drop-down. My first draft was pretty ugly, it ivolved getting the DOM from the child IFrame (by getting it&#8217;s contentWindow or contentDocument property) then getting the  of the DOM and looping over all [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I had to alter the stylesheets in a child IFrame when a user selected an item from a drop-down. My first draft was pretty ugly, it ivolved getting the DOM from the child IFrame (by getting it&#8217;s <a href="http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html">contentWindow</a> or <a href="http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref4.html">contentDocument</a> property) then getting the <head> of the DOM and looping over all the child items&#8230; yuck!</p>
<p>I coded up this jQuery extension method which will return a jQuery-wrapped DOM instance for any of the matched IFrames.</p>
<pre class="prettyprint"><code>
(function($) {
    $.fn.extend({
        dom: function () {
            var $this = $(this);
            var getDom = function(o) {
                if( !o || (!o.contentWindow &#038;&#038; !o.contentDocument) ) {
                    return null;
                }

                var doc = (o.contentWindow || o.contentDocument);

                return doc.document || doc;
            };

            var dom = getDom($this[0]);

            return dom === null ? $this : $(dom);
        }
    });
})(jQuery);
</code></pre>
<p>So with this, getting the styles for a child IFrame is as easy as:</p>
<pre class="prettyprint"><code>
$('iframe').dom().find('head link').each(function(index, item) {
    alert(item.href);
});
</code></pre>
<p><em>Unfortunately, this code will only work if your IFrame is hosting content that is on the same domain as its parent.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
