Closed Bug 237536 Opened 20 years ago Closed 20 years ago

Getelementbyid('id').innerHTML="this" doesn't work unless "id" div tags already contain something...

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
minor

Tracking

()

RESOLVED INVALID

People

(Reporter: lauriek, Assigned: bugzilla)

References

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206 Firefox/0.8
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206 Firefox/0.8

The following html works fine:-

<div id='helpcontent'>Help</div>
<script type="text/javascript">
<!--

var whichHelpPage="$helppage$";
opHtml="<font class='normal'><br>";

switch(whichHelpPage) {
        case "home":
                opHtml+="The Homepage consists of the following pages squeezed
into one easy to digest bite:-";
        break;
        default:
                opHtml+="The Homepage consists of the following pages squeezed
into one easy to digest bite:-";
        break;
}
opHtml+="</font><br><br>";
document.getElementById("helpcontent").innerHTML = opHtml;

// -->
</script>

But if you remove the initial content from the div at the top leaving

<div id='helpcontent'></div>

Then the getElementById("helpcontent").innerHTML method reports

document.getElementbyId("helpcontent") has no properties...

I /think/ this should be considered a bug and I've searched the lists of known
bugs but not come across this. Please forgive me for wasting your time if this
is one of those cases where IE is too forgiving and that this is correct behaviour!
Cheers!

Reproducible: Always
Steps to Reproduce:
1. Enter the html code in the details section above, try it - it works
2. Remove the initial content from the div and try again, it doesn't work..
3.

Actual Results:  
Firefox reports 
document.getElementbyId("helpcontent") has no properties...

Expected Results:  
It should have substituted in the variable I was passing in:-

document.getelementbyid("blah").innerHTML = htmlStuff

htmlStuff - into the DIV.
*** Bug 237541 has been marked as a duplicate of this bug. ***
Laurie, how about attaching a testcase that shows the bug?
http://bugzilla.mozilla.org/attachment.cgi?bugid=237536&action=enter
(In reply to comment #2)
> Laurie, how about attaching a testcase that shows the bug?
> http://bugzilla.mozilla.org/attachment.cgi?bugid=237536&action=enter

Hi.

'Bug' solved, my test case was the html snippet above, I am creating some pages 
to be SSI'd into another site so they do not have <html>, <head> or <body> 
tags. If i create a 'proper' html page like so:-

<head>
<title>GetElementById Bug</title>
</head>
<body>
<div id='helpcontent'></div>
<script type="text/javascript">
<!--

var whichHelpPage="$helppage$";
opHtml="<font class='normal'><br>";

switch(whichHelpPage) {
        case "home":
                opHtml+="The Homepage consists of the following pages squeezed 
into one easy to digest bite:-";
        break;
        default:
                opHtml+="The Homepage consists of the following pages squeezed 
into one easy to digest bite:-";
        break;
}
opHtml+="</font><br><br>";
document.getElementById("helpcontent").innerHTML = opHtml;

// -->
</script>
</body>
</html>

which I just did to make a file to send you then it seems to work okay, 
the 'bug' I mentioned only occurs if the html is invalid... Sorry to waste your 
time! I'll ensure I test this before logging any other bugs!

Great product, keep up the good work!
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Status: RESOLVED → UNCONFIRMED
Resolution: FIXED → ---
Nothing was fixed in Firefox, correcting resolution.

Thanks for testing Firefox!
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago20 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.