473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

can't get away from innerHTML

i've read that innerHTML is not in the W3C standards and never will be.
however i've found something that i simply can't do by manipulating
text nodes directly.

<div id="mydiv"></div>
<script type="text/javascript">
document.getElementById('mydiv').innerHTML='ide&ea cute; fixe';
</script>

this prints "idee fixe" with the final 'e' of idee having an acute
accent (the &eacute; entity).

however if i use this javascript instead:

var newNode = document.createTextNode("ide&eacute; fixe");
var oldNode = document.getElementById('mydiv').firstChild;
var removedNode = document.getElementById('mydiv').replaceChild(newN ode, oldNode);

this does not display an accented e. it displays the literal string & e a c u t e ;
(spaces inserted so your newsreader won't transform it)

personally i don't have any problems with innerHTML, despite it not being a
standard. however, i'd like to know for my own curiosity if there's a way
to get the innerHTML behavior with the DOM-approved node manipulation commands.
-rs-
Jul 23 '05 #1
3 1993
> personally i don't have any problems with innerHTML, despite it not being a
standard. however, i'd like to know for my own curiosity if there's a way
to get the innerHTML behavior with the DOM-approved node manipulation commands.


innerHTML exposes the HTML parser, which is a very handle tool to have.
Lacking it, you would have to do all the HTML parsing yourself, which is
a bad thing.

I think a better interface would have been to make the calling of the
parser explicit, like document.parseHTML(source). I don't like innerHTML
because I think that assignment should not have side-effects.

There are lots of features in the browsers which are useful and
necessary, and not specified in any standard. I think that is an
indication of the quality and completeness of the WWW standards.

http://www.JSON.org
Jul 23 '05 #2
On Wed, 05 Jan 2005 01:19:10 GMT, Ralph Snart <sn***@nospam.com> wrote:
i've read that innerHTML is not in the W3C standards and never will be.
Correct[1].

[snip]
(spaces inserted so your newsreader won't transform it)
It won't matter as you should be (and are) posting in plain text.
however, i'd like to know for my own curiosity if there's a way to
get the innerHTML behavior with the DOM-approved node manipulation
commands.


You'll have to specify the Unicode code point value (\u00e9). Character
references are within the domain of HTML, not client-side scripts. As the
HTML parser skips the content of SCRIPT elements, no translation occurs so
the script parser will still encounter the character reference and treat
it as literal text.

The exception is within intrinsic events. In this case, the HTML parser
*does* handle the content so character references will be translated. When
the script parser takes over later, it will find the actual character, not
the reference.

Mike
[1] Well, I couldn't guarantee that the second part is true, but it's
highly unlikely that innerHTML will ever be added to the W3C DOM.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3


Ralph Snart wrote:

<div id="mydiv"></div>
<script type="text/javascript">
document.getElementById('mydiv').innerHTML='ide&ea cute; fixe';
</script>

this prints "idee fixe" with the final 'e' of idee having an acute
accent (the &eacute; entity).

however if i use this javascript instead:

var newNode = document.createTextNode("ide&eacute; fixe");
var oldNode = document.getElementById('mydiv').firstChild;
var removedNode = document.getElementById('mydiv').replaceChild(newN ode, oldNode);

this does not display an accented e. it displays the literal string & e a c u t e ;
(spaces inserted so your newsreader won't transform it)


Of course, the DOM operates on utf-16 encoded strings, it has no idea
about HTML character references like &eacute;, but all you need to do is
use the appropriate character in a properly encoded documented e.g.
document.createTextNode("ideé")
If you want to rely on JavaScript to encode the character then you can use
document.createTextNode("ide" + String.fromCharCode(233))
or
document.createTextNode("ide\u00E9")

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4

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

Similar topics

5
by: Phil N | last post by:
Hello again Site I'm working on: http://www3.telus.net/bikim/lightning/test/ - 'coach' & 'main' links swap innerHTML of div element - id 'textArea' works fine in NN7; IE6 reports 'Object...
7
by: KK | last post by:
Please help! I am currently experiencing a bug in Safari v125.9. When I modify the value of form input box and then get the innerHTML property of the surrounding div object - I am returned the...
10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
4
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...
9
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...
8
by: Clément | last post by:
Hi! I am currently developping a user interface with Ajax/C#/.net. And I am facing a problem with Mozilla, and Firefox. I use the function innerHTML to load a Web UserControl into a div, this...
8
by: Pratik Patel | last post by:
Hello, I used innerHTML to assign HTML content. but in my HTML page content have also some javascript function and it will run when page load. bu when HTML code assgin thru innerHTML then this...
9
by: art | last post by:
Hi, We have some scripts here where we use some AJAX to populate some of the page. Basically the AJAX routine calls a PHP script. That PHP script uses a bunch of ECHO statements to create...
13
by: fulio pen | last post by:
I have following page: http://www.pinyinology.com/test/testGet.html Part of the code is: javascript: document.getElementById("moon1").innerHTML ="moon";...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...

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.