473,748 Members | 7,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ampersand creating problem in IE6 innerHTML property

I am setting the content of a div dynamically using innerHTML
property. If the content contains an ampersand, text after the
ampersand is disappearing in IE6. It works properly in Firefox.

This is my code:
----------------
<body>

<div id='div1'></div>
<script>
var div = document.getEle mentById('div1' );
div.innerHTML = "A&B";
</script>

</body>
---------------

IE6 renders the content of div1 as 'A'
Firefox renders the content properly as 'A&B'

If there is a space after ampersand, IE6 renders it properly. So I
think that IE is assuming anything after ampersand as an HTML entity
( like &nbsp; ).

Is this a bug in IE6? Is there any workaround for this?

Thanks
Kiran Makam
Aug 26 '08 #1
4 4224
Kiran Makam wrote:
div.innerHTML = "A&B";
Is this a bug in IE6? Is there any workaround for this?
No, it is not a bug, the ampersand needs to be escaped as &amp;
(& a m p ; without the blanks) e.g.
div.innerHTML = "A&amp;B"

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 26 '08 #2
Kiran Makam wrote:
I am setting the content of a div dynamically using innerHTML
property. If the content contains an ampersand, text after the
ampersand is disappearing in IE6. It works properly in Firefox.
It works properly in both UAs, because there is no public standard that
defines how syntax errors MUST be handled. The HTML 4.01 Specification only
makes suggestions in that regard:

<http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.1>
This is my code:
----------------
<body>
The DOCTYPE declaration and the required `title' element are missing.
<div id='div1'></div>
<script>
The #REQUIRED `type' attribute is missing.
var div = document.getEle mentById('div1' );
You should do feature tests before you call anything.
div.innerHTML = "A&B";
See below.
</script>

</body>
---------------

IE6 renders the content of div1 as 'A'
That is correct.
Firefox renders the content properly as 'A&B'
That is also correct.
If there is a space after ampersand, IE6 renders it properly.
And that is correct as well.
So I think that IE is assuming anything after ampersand as an HTML entity
( like &nbsp; ).
Which is standards compliant.
Is this a bug in IE6?
No, the bug is in your code.
Is there any workaround for this?
Either

&amp;

or (better) using standards-compliant properties instead of the proprietary
`innerHTML' property.

Validate your code before you complain about browsers next time.

<http://validator.w3.or g/>
<http://jibbering.com/faq/>
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Aug 26 '08 #3
Kiran Makam wrote:
var div = document.getEle mentById('div1' );
div.innerHTML = "A&B";
The logic is that innerHTML considers the string as HTML; so '&...;'
should represent a valid numeric or character entity reference, while
(the avoidable) innerText considers it as the literal text.

--
Bart
Aug 26 '08 #4
Thanks to all.

Kiran Makam
Aug 26 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5146
by: alex bazan | last post by:
This piece of code (which works as a charm with Mozilla) ... does not append new rows to the table in explorer, although the code is appended to the innerHTML property. <html> <body> <script> function newItem () {
3
1327
by: Lance | last post by:
I have quite an odd question. Usually I ask whenever javascript is not acting the way I'd expect. This time I'm trying to figure out why something works when I don't think it should be working! I'm working on a web page that has a <div> area for dynamic content display (id='content'). In between the </body> and </html> tags is where I'm storing the text to be displayed when needed. They are stored inside wrapper <div>s which are...
4
6552
by: RobG | last post by:
I know you aren't supposed to use innerHTML to mess with table structure, but it seems you can't use it just after a table without damaging the containing element. I added a table to a div using createElement methods, then added a bit of extra text using innerHTML, only to find most of the attributes removed from the table. Below is a script that calls the same code to add a table inside a div. It adds an onclick to the div and...
9
8669
by: Hallvard B Furuseth | last post by:
Why does the FAQ (Q 4.15) recommend innerHTML when so many here say one should use createElement(), replaceChild() etc? Also, why does the "Alternative DynWrite function" at <http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html> need such a lot of tests to find out if innerHTML assignment actually works, instead of just inserting <span id="strange name"></span> and checking if the document now contains an element with that ID?
4
2092
by: Casper | last post by:
I currently have this code: <script language="javascript"> function init() { // load XML source document var source = new ActiveXObject("Msxml2.DOMDocument.4.0"); source.async = false; source.load("record49a36bde.xml");
3
1885
by: lcjohnso | last post by:
Hi all, Does anyone know if there is an easy way to create the html representation of an HTMLElement object in javascript? I'm attempting to update the innerHTML property of a div element to allow user entries to presist when the the input display pane is changed. Basically I have several different div panes that users can rotate through when entering values of a simulated form whose values are then parsed and used to dynamically...
2
4936
by: Moses | last post by:
Hi All, Is is possible to catch the error of an undefined element while creating an object for it. Consider we are not having an element with id indicator but we are trying to make the object for it indicator = document.getElementById('indicator');
9
3398
by: martymix | last post by:
simple question: I have a simple <dt>test text</dt> I get the innerHTML of that dt, and I try and append some text to it like so: dt = document.getElementsByTagName('dt') var text = dt.innerHTML + 'new' in Firefox, I get "test textnew"
6
4253
by: PaPa | last post by:
I'm not sure this is a javascript issue or an HTML issue. I notice that when I extract the contents of a div using the innerHTML property (?), that I wind up with a literal variable (?) which exactly matches the contents of the div with one exception. It seems that whenever the code includes a tag which uses the forward slash against the closing bracket (say the break tag ..... />) that the browser, or HTML, or javascript, or...
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.