Solved

innerText, IE, and Netscape

Posted on 2004-04-21
5
5,684 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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
Non-Resizable Pharagraph 2 17
Use Mid in Html 6 21
Prevent certain words from being typed in a form 6 24
Check input text, Number 6 26
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

685 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