...

View Full Version : Using innerHTML in IE



MattJakel
07-14-2004, 10:44 PM
EDIT: I found the problem. Apparently innerHTML in IE only works with <td>s and not <table>s.

Nothing I write in JS ever works in IE after i get it to work in Mozilla lol. I have this function that is called when an image is clicked and makes everything inside of a table disappear. Here's the code:



function col(id)
{
var tabToChange = document.getElementById(id);
tabToChange.innerHTML = "";
}


This is how I call it:



<a href="#" onclick="javascript:col('tableid');"><img src="src.ext"></a>


What am I doing wrong here?

Thanks,
Matt

MattJakel
07-14-2004, 11:38 PM
Ok, I'm having a new problem, this time with a regular expression. Once again it works in everything but IE. Here's the code:



var thing = tabtochange.innerHTML;
toUncomment = new String (thing);
toUncommentres = toUncomment.replace(/<!--jsinsert/, "");
toUncommentdos = new String (toUncommentres);
tabtochange.innerHTML = toUncommentdos.replace(/jsinsert-->/, "");


What am I doing wrong?

Thanks,
Matt

SlySecretSpy
07-14-2004, 11:55 PM
They are going to ask you to post different questions separately .

As for your innerHTML question. A <table> does not have an innerHTML property. <table> has <tr> children, which have <td> children which have textNode children or a innerHTML.

Mozilla's ability to do what you want is suspect to say the least.

SlySecretSpy
07-15-2004, 12:01 AM
<table>
<tr id="one"><td>one</td></tr>
</table>
<A href="#" onClick="document.getElementById('one').style.visibility='hidden'">one</A>

Here is the easiest way to hide the table data. Unless you want to code a loop to remove the elements.

MattJakel
07-15-2004, 12:13 AM
The problem with that is that I need the space where it was to be used by something else while it's hidden, so the only way I know to do that is to set the innerHTML to "" or (as I decided to change it to) placing comment tags around the innerHTML, which is why I need the regular expressions to work.

Thanks,
Matt

dumpfi
07-15-2004, 12:37 AM
If you set the elements display-attribute to 'none' the element should take up no space on the site anymore, e.g.:

<a href="javascript:document.getElementById('tableid').style.display = 'none'"><img src="src.ext"></a>

dumpfi

MattJakel
07-15-2004, 01:24 AM
Thanks Spy and dump! That style.display property got it!

Matt



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum