?
Solved

innerText, IE, and Netscape

Posted on 2004-04-21
5
Medium Priority
?
5,696 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 500 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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

752 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