Solved

innerText, IE, and Netscape

Posted on 2004-04-21
5
5,682 Views
Last Modified: 2011-08-18
OK.  I've got this javascript that sets the innerText of a <span> element on a button click.  This works great in IE.  It does not work in Netscape.  So the question is, what do I need to change in the code below to make it work in both IE and Netscape?

*******************Code Starts Here********************
function nextPic()
{
  if(curPic>=imgs.length-1){curPic=0;}else{curPic++;}
  document.img.src=images[curPic].src;
  document.all.imgspan.innerText=curPic+1 + " of " + imgs.length;
}
*****************************************************

Thanks
0
Comment
Question by:dds110
5 Comments
 
LVL 30

Expert Comment

by:third
ID: 10884267
just change innerText to innerHTML
0
 
LVL 4

Accepted Solution

by:
apprenti earned 125 total points
ID: 10884333
If "imgspan" is the relevant container try replacing
document.all.imgspan.innerText
with
document.getElementById("imgspan").innerHTML
0
 
LVL 30

Expert Comment

by:third
ID: 10884397
nice catch apprenti! i missed 'document.all' which is IE only.

dds110,

just make sure that your span has an id attribute named 'imgspan' and it will work.

<span id="imgspan"></span>

document.getElementById works IE5+, NS6+
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10890468
This works in IE6.0 and Mozilla1.5:

<html>
<head>
<script>
var curPic = -1;
var imgs = ["images/Holiday1.jpg", "images/Holiday2.jpg", "images/Holiday3.jpg"];
for(i=0;i<imgs.length;i++){
  newImg = new Image();
  newImg.src = imgs[i];
  imgs[i] = newImg;
}
function nextPic(){
 if(curPic>=imgs.length-1){curPic=0;}else{curPic++;}
 document.images["img"].src=imgs[curPic].src;
 document.getElementById("imgspan").innerHTML=curPic+1 + " of " + imgs.length;
}
</script>
</head>
<body onLoad="nextPic()">
<img name="img" src="images/Holiday1.jpg">
<a href="javascript:nextPic()">Next</a>
<span id="imgspan"></span>
</body>
</html>


0
 
LVL 8

Author Comment

by:dds110
ID: 10895480
thanks guys/gals.  finally got it to work.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Allow tab to be displayed without being clicked and active color border changed 2 32
Jquery 2 23
removing a class in javascript 4 47
Javascript 2 21
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question