473,770 Members | 4,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentById('mydiv ').innerHTML='i de&eacute; 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.create TextNode("ide&e acute; fixe");
var oldNode = document.getEle mentById('mydiv ').firstChild;
var removedNode = document.getEle mentById('mydiv ').replaceChild (newNode, 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 2024
> 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.parseH TML(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.c om> 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.getEle mentById('mydiv ').innerHTML='i de&eacute; 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.create TextNode("ide&e acute; fixe");
var oldNode = document.getEle mentById('mydiv ').firstChild;
var removedNode = document.getEle mentById('mydiv ').replaceChild (newNode, 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.create TextNode("ideé" )
If you want to rely on JavaScript to encode the character then you can use
document.create TextNode("ide" + String.fromChar Code(233))
or
document.create TextNode("ide\u 00E9")

--

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
8452
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 doesn't support this property or method' code is:
7
3474
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 original form value not the changed value! Has anyone else encountered this? Cheers.
10
4590
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 reverse of embedding JS in an html page with the script tag. (which is what I am doing in this case) Is this even possible?
4
6553
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
8671
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?
8
7773
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 way the main page never gets refreshed. It works perfectly under IE, but with Mozilla and Firefox I got a problem : there is a space before the thing I want to display everytime I use ".innerHTML".
8
3218
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 javascript is not working. e.g. html content:
9
1781
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 the page. Then, we use the innerHTML to populate the section on the page. The problem is, we have a small javascript routine in the middile of
13
1423
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"; document.getElementById("moon2").innerHTML ="moon"; document.getElementById("moon3").innerHTML ="moon";
0
9592
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
9425
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
10231
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10005
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
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
7416
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
6679
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
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...
3
2817
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.