Closed Bug 114749 Opened 23 years ago Closed 23 years ago

setting of embedded divs innerHTML using javascript fails

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

VERIFIED DUPLICATE of bug 26179

People

(Reporter: deskamess, Assigned: jst)

Details

From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.6) Gecko/20011120
BuildID:    2001112009

If you have a div (child) embedded in another div (parent), and try to set the
childs innerHTML using document.getElementById("parent").firstChild.innerHTML,
changes are not visible in the browser. However, if you access the child
directly by name [document.getElementById("child").innerHTML], all is well. Best
illustrated with the following html code:

<html>
<head>
<title>innerhtml check</title>

<script type="text/javascript" language="javascript">

function writeToChildOf(obj) 
{
	var oListHandle = document.getElementById(obj).firstChild;
	oListHandle.innerHTML = "Child Div innerHtml Changed. No bug.";
}

</script>

</head>

<body>

<a href="javascript://" onclick="writeToChildOf('aParent')">Test</a> 	

<div id="aParent">
	<div id="aChild"> Click on Test to change this message. No change => bug. </div>
</div>

</body>
</html>


Reproducible: Always
Steps to Reproduce:
Load above html code into browser. Click on Test.

Actual Results:  
Test
Click on Test to change this message. No change => bug.


Expected Results:  
Test 
Child Div innerHtml Changed. No bug.

The problem exists not just with embedded DIVs, but also SPANS embedded  in a
DIV. ie, <div><span>blah</span></div>.

Works as expected under IE 6. Since innerHTML was copied over from IE, I guess
compliance with IE behaviour is more or less what people would come to expect.
innerHTML is working fine.  firstChild for the outer div, however, is a Text
node corresponding to the line break you have in the source, not an Element
node.  Text nodes don't have a way to set their innderHTML

*** This bug has been marked as a duplicate of 26179 ***
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
Boris, you're too fast for me ;-)
VERIFIED dup.
Status: RESOLVED → VERIFIED
QA Contact: lchiang → ian
Component: DOM: Mozilla Extensions → DOM
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.