I have a fairly complicated application written in Javascript+DOM, and
I've run into an odd problem that only shows up in Safari. Basically,
after setting innerHTML of a DIV, the div ends up empty instead of with
the correct content. In fact, the children of the DIV all vanish, and
it becomes impossible to set the contents thereafter.
The much simplified scenario:
<div id='divname'>
hello
</div>
var divReference = document.getElementById('divname');
divReference.innerHTML = 'loo loo loo';
alert(divReference.innerHTML);
At this point the laert box is empty. Also, when I iterate through the
properties of the divReference, they are quite messed up. For example,
firstChild and lastChild are null. Also, some properties are
duplicated.
Has anybody run into this? Unfortunately I have been unable to
reproduce in a simple test app, it seems to only happen in my
complicated app.
Also, please don't advise me to use DOM instead of innerHTML. I know
DOM is more elegant and correct, unfortunately it would be very
complicated given the amount of content I want to be pushing around.
Thanks,
Garth 7 9291
just at a quick first glance. i see you've single-quoted your div's
id. id='divname'. have you tried double quoting in your actual code?
some browsers can be super picky about those things.
Thanks for the suggestion. I wasn't aware that there was any difference
between ' and " in HTML. However, switching to double quotes didn't
make any difference.
Garth
one more thought, just a shot in the dark- in your much more complex
app, i'm guessing that you're using innerHTML to dump a lot of HTML
into that div tag. have you made sure that String of HTML is valid?
often times when i write big long Strings of HTML and stick them in a
div using innerHTML, i find that i've messed up a set of quotes
somewhere or haven't closed a tag properly.
Yup, I'd thought of that. When I found the point where it failed (as
shown in previous message) I changed the complex HTML string to a
simple text only string. It still failed.
"Walton" <jr******@gmail.com> writes: just at a quick first glance. i see you've single-quoted your div's id. id='divname'. have you tried double quoting in your actual code? some browsers can be super picky about those things.
They shouldn't. Either way of quoting attributes has been valid since
the first versions of HTML. It should not make a difference.
(Ofcourse, if the attribute value contains an apostrophe, you'll
either have to quote it or use double quotes, e.g.,
title="it's fun"
or
title='it's fun"
and failing to do that would make the browser "picky", and rightly so)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.' ga*********@gmail.com wrote: I have a fairly complicated application written in Javascript+DOM, and I've run into an odd problem that only shows up in Safari. Basically, after setting innerHTML of a DIV, the div ends up empty instead of with the correct content. In fact, the children of the DIV all vanish, and it becomes impossible to set the contents thereafter.
There is a bug reported at quirksmode regarding innerHTML in XHTML pages:
<URL:http://www.quirksmode.org/bugreports/archives/2004/11/innerhtml_in_xh.html>
I don't know whether that covers your scenario or not.
The much simplified scenario:
<div id='divname'> hello </div>
var divReference = document.getElementById('divname'); divReference.innerHTML = 'loo loo loo'; alert(divReference.innerHTML);
At this point the laert box is empty. Also, when I iterate through the properties of the divReference, they are quite messed up. For example, firstChild and lastChild are null. Also, some properties are duplicated.
Has anybody run into this? Unfortunately I have been unable to reproduce in a simple test app, it seems to only happen in my complicated app.
That would indicate that there are possibly errors in the HTML you are
inserting, the differences between browsers in the generated DOM may be
the result of error correction.
Post a link to a page that shows the error, or try validating the HTML
you are trying to insert.
Also, please don't advise me to use DOM instead of innerHTML. I know DOM is more elegant and correct, unfortunately it would be very complicated given the amount of content I want to be pushing around.
There is no public standard for innerHTML, so you can't depend on it
being implemented consistently. It generally works OK where the HTML is
generated elsewhere then inserted, but if you are trying to read the DOM
using innerHTML then insert it back in again, results will vary between
browsers.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/> ga*********@gmail.com a écrit : Also, please don't advise me to use DOM instead of innerHTML. I know DOM is more elegant and correct, unfortunately it would be very complicated given the amount of content I want to be pushing around.
unfortunatly Safari (and probably Firefox) using innerHTML for complex
code (elements with events, datas comming from text-field ...) loose
quite a bit of important infos ...
innerHTML would be only used for some text, no more.
but, perhaps in your innerHTML you have closing tags ?
and, of course you use '<\/tag>' insteed of '</tag>' ?
--
Stephane Moriaux et son [moins] vieux Mac This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: rob |
last post by:
I know IE first supported it, and Mozilla supports it, what about Opera
and Safari? IE 5 on the mac does, right?
many thanks
|
by: kaeli |
last post by:
Hey all,
AFAIR, innerHTML started as MS proprietary, but Mozilla implemented it
as well. Does anyone know if any other browsers support it? It is not in
the W3C DOM, is it? A quick GIS seemed to...
|
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...
|
by: mtz |
last post by:
Hi there,
It looks like safari has a problem with innerHTML. I have to change a
dropdown depending on a selection in another dropdown. When I change
the selection in the first dropdown the...
|
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...
|
by: Jake Barnes |
last post by:
This weekend I wanted to learn AJAX, so I set up a little toy page
where I could experiment. The idea of this page is that you click in
one of the boxes to get some controls, at which point you can...
|
by: xhe |
last post by:
I met a very headache problem in javascript, I think this might be
difference between IE and NS / Safari.
I have a text area
<form>
<textarea name='tex1' onkeyup='displayit();'></textarea>...
|
by: Dmitry Khudorozhkov |
last post by:
Hi everyone!
I have a html page with an IFrame; and the following code:
var doc = document.getElementById("iframe_id").contentDocument;
doc.body.innerHTML = htmlCode;
This code is run in...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |