PDA

View Full Version : setting innerHTML has no effect


BubikolRamios
10-01-2006, 01:05 AM
why does "b" doesn't change to "dddddddddd". here is the link to below code-->

http://86.61.66.17:8084/AgroZoo/testHTML/testHTML.html

click on fffff

thanks for help.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function setTargetChildInnerHTML(parentNodeObj,subElementCount)
{
var groupArray = parentNodeObj.getElementsByTagName("DIV");
//alert(parentNodeObj.getElementsByTagName("DIV"));
var TDnodeObj = groupArray[subElementCount];
alert(groupArray[1].id);
groupArray[1].innerHtml ="dddddddddd";
}
</script>
</head>
<body id = 'BODYID' onLoad = 'myFunc()'>

<div onClick = 'setTargetChildInnerHTML(this,1)'>
ffffff
<div id = 'child0'>
a
</div>
<div id = 'child1'>
b
</div>
<div id = 'child2'>
c
</div>
</div>
</body>
</html>

BubikolRamios
10-01-2006, 01:38 AM
solved:

-->

http://86.61.66.17:8084/AgroZoo/testHTML/testHTML.html



while(groupArray[1].firstChild) groupArray[1].removeChild(groupArray[1].firstChild);

groupArray[1].appendChild(document.createTextNode("dddddddddd"));




but this look messy, is there any cleaner solution ?

syosoft
10-01-2006, 05:55 AM
hrm...seems to me using something like

groupArray[1].firstChild.innerHTML = 'dddddd'; would be logical, but i havent bothered w/ the code, so could be completely wrong. Dom is tricky.

kschaeuble
10-10-2006, 04:08 PM
Yes, you have to write innerHTML, notice the upper case HTML.
I had the same problem and tried days to find it, especially as no debugger saw this as a problem.

Kor
10-11-2006, 08:56 AM
the problem in your first code is that you have used lowercase innerHtml instead of the correct innerHTML

On the other hand innerHTML is not a standard DOM method. DOM is

element.firstChild.data
or
element.firstChild.nodeValue