<?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>Remember the code? &#187; IE</title>
	<atom:link href="http://code.neox.net/tag/ie/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.neox.net</link>
	<description>a place where I store my secret powerful coding snippets, or just to remember how to do things</description>
	<lastBuildDate>Fri, 19 Jun 2009 11:36:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>IE innerHTML property and NoScope element such as &lt;script&gt; and &lt;style&gt;</title>
		<link>http://code.neox.net/2008/06/02/ie-innerhtml-property-and-noscope-element-such-as-script-and-style/</link>
		<comments>http://code.neox.net/2008/06/02/ie-innerhtml-property-and-noscope-element-such-as-script-and-style/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 01:02:59 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[Javascript and CSS]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=30</guid>
		<description><![CDATA[OK , I was working this my random sidebar image rotator. It uses ajax component to get html codes to show random images and it automatically rotates the image in every defined seconds.
In order to show horizontal and vertical images in a same spaced area, I have assigned pre defined squre div element and make [...]]]></description>
			<content:encoded><![CDATA[<p>OK , I was working this my random sidebar image rotator. It uses ajax component to get html codes to show random images and it automatically rotates the image in every defined seconds.</p>
<p>In order to show horizontal and vertical images in a same spaced area, I have assigned pre defined squre div element and make the ajax component to get html codes and set innetHTML property of this <code>&lt;div&gt;</code> element. The <code>&lt;img&gt;</code> element should be aligned in the center using calculated top and left CSS property.</p>
<p>So this is what I wanted to display (Normal) viewd with Firefox.<br />
<img src="http://code.neox.net/wp-content/uploads/2008/06/normal.jpg" alt="" title="normal" width="184" height="183" /></p>
<p>But when I tried with IE 7, I got below. It seems as if the <code>&lt;style&gt;</code> tag didn&#8217;t exist. The image was not aligned properly in the center.<br />
<img src="http://code.neox.net/wp-content/uploads/2008/06/abnormal.jpg" alt="" title="abnormal" width="184" height="183" /><br />
<span id="more-30"></span><br />
Here is my div injecting HTML code.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
.hana_ri {
	position: relative;
	width:180px;
	height:180px;
	/*border: 1px dashed grey;*/
}
&nbsp;
.hana_ri span {
	position: absolute;
	width: 51px;
	height: 19px;
	display:block;
&nbsp;
	top:80px;
	left:64px;
	background: url(http://localhost/wp/wp-content/themes/classic.neox/progress.gif) no-repeat;  
}
.hana_ri img {
	top:22.5px;
	left:0px;	
	position: absolute;
	width: 180px;
	height:135px;	
}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hana_ri&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/wp/pics/IMG_2716.jpg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> 
<span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://localhost/wp/wp-content/themes/classic.neox/hana_random_image.php?image=IMG_2716.jpg&quot;</span> 
<span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;IMG_2716.jpg&quot;</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hana_ri_span&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></pre></div></div>

<p>My code looks OK. I tried almost anything blaming and cursing the IE, why it has to be so difficult to do a simple thing. Searching Internet for any hints.</p>
<p>And I finally got my answer from Microsoft MSDN Website. <a href='http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx'>This is a link MSDN regarding innerHtml property</a> of html element. It&#8217;s a nice little reference about innerHTML property. If you keep scrolling down to the bottom, there is a comment made by a user. It&#8217;s title is  &#8220;How to inject NoScope elements into a page with innerHTML.&#8221; </p>
<p>This is the quote from the comment.</p>
<blockquote><p>
Internally, Internet Explorer treats the <code>&lt;script&gt;</code> tag as a NoScope element, which means (according to a rather opaque comment in the source) that &#8220;no text in a textrun should point to it.&#8221; Examples of other tags that have this attribute are HTML comments <code>(&lt;!-- --&gt;)</code> and STYLE tags. All NoScope elements are removed from the beginning of the parsed HTML before it is injected with innerHTML or insertAdjacentHTML. To prevent this from happening, you must include at least one scoped element at the beginning of the injected HTML.</p>
<p>To make it work, you must start the injected HTML string with a scoped element, preferably an invisible one like a hidden input element.
</p></blockquote>
<p>So basically the user is suggesting to start the innerHTML with the regular scoped element. He is suggesting to start with <code>&lt;input&gt;</code> with hidden attribute. If the innerHTML starts with <code>&lt;style&gt;</code>, IE will simply ignore it.</p>
<p>So I immediately changed the code and made the &lt;style&gt; to come after &lt;div&gt; element. And viola! , it worked just like a magic!!!!! I really appreciate &#8216;John Sudds&#8217;, the commenter.</p>
<p>So here is the final version that worked.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hana_ri&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/wp/pics/IMG_2716.jpg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> 
<span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://localhost/wp/wp-content/themes/classic.neox/hana_random_image.php?image=IMG_2716.jpg&quot;</span> 
<span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;IMG_2716.jpg&quot;</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hana_ri_span&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
.hana_ri {
	position: relative;
	width:180px;
	height:180px;
	/*border: 1px dashed grey;*/
}
&nbsp;
.hana_ri span {
	position: absolute;
	width: 51px;
	height: 19px;
	display:block;
&nbsp;
	top:80px;
	left:64px;
	background: url(http://localhost/wp/wp-content/themes/classic.neox/progress.gif) no-repeat;  
}
.hana_ri img {
	top:22.5px;
	left:0px;	
	position: absolute;
	width: 180px;
	height:135px;	
}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style&gt;</span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/06/02/ie-innerhtml-property-and-noscope-element-such-as-script-and-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
