0

I have a rotating slide show I'm working on that uses Javascript. I use a counter in the function, and I want to display the value of the counter each time the image changes. (so it will say "viewing i of x pictures")

I tried using

<script language="javascript" type="text/javascript">document.write(i);</script>

but it only displays the value of i when the page loads, and it won't update each time i increases. Is there something better than document.write(i) that will update each time i increases or decreases?

1

2 Answers 2

4

In your HTML, instead of the above SCRIPT tag have something like this:

<div id="counter"></div>

In your Javascript function where the counter value updates, have the following line:

document.getElementById('counter').innerHTML = i;
Sign up to request clarification or add additional context in comments.

Comments

2

wrap the value in a div or span or something similar and include an id attribute. When the image changes, increment i and update the document.getElementById('dividhere').innerHTML with i

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.