Newsgroup: it.comp.lang.javascript
Titolo: Script works in IE 6, but not Firefox -- Need Help!

I'm trying to figure out why this script will work in IE 6 but not
Firefox, and so I need someone here with a far better grasp on
javascript to explain this.   Basically, I have a page with several
thumbnails.  Above these thumbnails I placed a large picture with text
next to it to describe what the picture is about.  So, when you click a
thumb, the large pic AND text change dynamically to reflect the
thumbnail -- see 
http://www.chadsmoore.com/pjstarhomeless
  -- for a
live example.
The scripts on my web page are located in the head section.  I have
provided the script below .   The "while" condition is used to prevent
the text from appending to each other after each click.
This script works perfectly in IE 6, but won't work in Firefox.
Any suggestions to making this work in Firefox would be greatly
appreciated.
Thanks in advance!
// script to change text -- thumbnail 1
function homelessbwWoman(){
while (content.hasChildNodes()) {
     content.removeChild(content.lastChild);
}
var txt = 'Tamara Maslanka takes a telephone call for a client at the
Illinois Valley Public Action to Deliver Shelter location in Ottawa.
Maslanka now directs operations at the shelter where she and her family
once lived.';
var txtn= document.createTextNode(txt);
document.getElementById("content").appendChild(txtn);
}
// script to change text -- thumbnail 2
function homelessbwFlorist(){
while (content.hasChildNodes()) {
     content.removeChild(content.lastChild);
}
var txt = 'Robert Maslanka puts together a floral arrangement at TPM
Stems in Ottawa. The upscale floral and interior landscape design shop
hired Maslanka while he and his wife resided at the IVPADS shelter. The
job, with hours donated by other employees, helped the Maslankas get on
their feet and out of a homeless situation.';
var txtn= document.createTextNode(txt);
document.getElementById("content").appendChild(txtn);
}
// Change Image Script
function canManipulateImages() {
		if (document.images)
			return true;
		else
			return false;
	}
	function loadHomelesslg(imageURL) {
		if (gImageCapableBrowser) {
			document.homelessLG.src = imageURL;
			return false;
		}
		else {
			return true;
		}
	}
	gImageCapableBrowser = canManipulateImages();
// relevant body code
<tr>
<td width="240">
<!-- Large Image -->
   <img src="thumbnails/bwWoman_lg.jpg" height="174" width="240"
id="homelessLG" name="homelessLG" alt="" />
</td>
											  <td>
<!-- Div element named "content" containing dynamic text -->
<div  id="content"  class="picContent">
																   Tamara Maslanka takes a telephone call for a client
at the Illinois Valley Public Action to Deliver Shelter location in
Ottawa. Maslanka now directs operations at the shelter where she and
her family once lived.
</div>
</td>
 </tr>
// Two cells each containing clickable thumbnails
<table>
<tr>
       <td>
<a href="#" onclick="homelessbwWoman();
return(loadHomelesslg('thumbnails/bwWoman_lg.jpg'));"><IMG
            alt=DAILY_PICS-MASLANKA1_BW
            src="thumbnails/bwWoman_th.jpg"
            width="75" height="56"></a>
       </td>
        <td>
			          <a
            href="#"  onClick="homelessbwFlorist();
return(loadHomelesslg('thumbnails/bwManFloral_lg.jpg'));"  ><IMG
            alt=DAILY_PICS-MASLANKA3_BW
            src="thumbnails/bwManFloral_th.jpg"  width="75"
height="56"></a>
 
                     </td>
             </tr>
</table>

I think it's because your variable 'content' isn't assigned explicitly.
You need a line
like this that is executed when the document loads
<body onload="content = document.getElementById( 'content' );">
 or just place it at the bottom of the page.
<script type="text/javascript">
  content = document.getElementById( 'content' );
</script>
</html>
I think IE will attempt to find the element with id 'content' if you
haven't defined it as a variable.


 haven't defined it as a variable.
Awesome.  Problem solved.  Thanks a million, bobzimuta!