0

I'm using jquery mobile to make an app. I'm playing a sound file when the page loads and displaying an image to turn the sound file off when clicked. everything is working fine however I can only get the image to change on the index page. I can turn off the sound file on any page however the image wont change on any other page. please help =) <3

<script type="text/javascript">
var newsrc = "soundOff.png";

function changeImage() {
    var sample = document.getElementById("foobar");
    sample.pause();

    if ( newsrc == "soundOff.png" ) {
        document.images["sound"].src = "/img/soundOff.png";
        document.images["sound"].alt = "Sound Off";
        newsrc  = "soundOn.png";
    }
    else {
        var sample = document.getElementById("foobar");
        sample.play();
        document.images["sound"].src = "/img/soundOn.png";
        document.images["sound"].alt = "Sound On";
        newsrc  = "soundOff.png";
    }
}
var sample = document.getElementById("foobar");
sample.play();

2
  • Could you post the file structure that you have, because that might be the issue if the paths are not correct. Commented Sep 17, 2013 at 18:38
  • 3
    This question IS NOT about jQuery. Commented Sep 17, 2013 at 18:40

1 Answer 1

1
document.images["sound"].src = "/img/soundOff.png";

Should be this:

document.getElementById('your_id').src = "/img/soundOff.png";

Your path seems a little wierd to me.Check it properly

Sign up to request clarification or add additional context in comments.

3 Comments

Everything works fine apart from the image will only change on the index page. It would change on anyother page :/
Yes you are right, it is the path however I am unsure what to change it too. Shouldn't the / take it to the root folder? Working on wamp.
myproject->images->profilepic.jpg...assume i have a folder like this.This is how i give the path considering your file is outside images. images/propic.jpg

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.