Solved

innerText, IE, and Netscape

Posted on 2004-04-21
5
5,673 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now