Solved

innerText, IE, and Netscape

Posted on 2004-04-21
5
5,685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Anyone familiar with PhotoSwipe? 3 41
Horizontal Full Calendar using php 5 42
Angular2 remove duplicates 11 24
Javascript image manipulationcrop-image 7 41
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…
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…

734 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