aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes innerHTML in InternetExplorer not working as expected Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "innerHTML in InternetExplorer not working as expected" Watch "innerHTML in InternetExplorer not working as expected" New topic
Author

innerHTML in InternetExplorer not working as expected

John Robert
Ranch Hand

Joined: Jun 17, 2008
Posts: 39
Hello Ranchers,
I am having difficulty understanding how innerHTML function works in Internet Explorer.

I have a jsp where on click, calls a ajax function and the textresponse of the ajax is set

back to the block using inner HTML.

Here is a part of my jsp


Note:I had to use 'onClik' instead of the actual 'onClick' because while posting I had some error.

This code works fine(both makelist and clearlist) in both IE and Mozilla Fire Fox.

However if i change the temp variable in javasript to 'display2' or 'display3'(as you can

see these are the ids of the table and tbody tags respectively), it does not work in IE but

works perfectly fine in firefox. So is it that innerHTML can only be appplied to div tags in

IE and not to any other tags? I read on googling that there is some bug in IE about

innerHTML, is this the one? I am using IE 7.0.
Am I missing something here?? Any response would be appreciated.
[ October 19, 2008: Message edited by: John Robert ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56151
    
  13

Tables are weird and restrictive. Are you trying to inject valid HTML into the table? If not, IE may be correctly balking.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
John Robert
Ranch Hand

Joined: Jun 17, 2008
Posts: 39
Originally Posted by Bear Bibeault
Are you trying to inject valid HTML into the table?


Thanks for the response. Yes I am trying to inject HTML something like this from the xmlhttp.responseText into the page.

I even tried just injecting the rows something like this, as the element is already a table or table body(when i set the temp variable to 'display2' or 'display3'


I am just trying to think how the innerHTML works, shouldnt it be able to put/clear Html on any block which has a start and end tag? May be i will use the div tag for now, it seems more stable and works as expected. But just wanted to know did any one face the same issue, or is it not working because I am doing something wrong. Well I think I am doing it right because it works in Fireforx perfectly.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
http://ajaxian.com/archives/innerhtml-gotchas

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56151
    
  13

Well it wouldn't be the first time someone's found a browser problem doing a particular task -- especially with tables (which can be finicky) and I believe that IE has particular problems with innerHTML and some types of elements. I don't have a Windows instance at my disposal so I can't try to recreate your issue.
[ October 19, 2008: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56151
    
  13

Aha! Eric snuck in his post while I was typing -- confirms my suspicion about IE and innerHTML and tables.
John Robert
Ranch Hand

Joined: Jun 17, 2008
Posts: 39
That answers why it wasnt working on IE. I also found out that this problem has been there for a while..i hope they fix it in the future.
Appreciate all the help..
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: innerHTML in InternetExplorer not working as expected
 
Similar Threads
cloning labels
document.getElementbyId not working inside table
Help me to have a sortable table in my html profile!
Creating CSS class at runtime
innerHTML with drop down box not working with IE