-1

I am a javascript beginner.

function PlayPause() {
if (playing) {
    playing = false;
    v*****s.pause();
} else {
    playing = true;
    v*****s.play();
}
};

what I want is add a line which change the source of an image in my html code. do exist something like this

function PlayPause() {
if (playing) {
    playing = false;
    Vianeos.pause();
    src="img_1"
} else {
    playing = true;
    Vianeos.play();
    src="img_2"
}   
};

I hope that you understand what I mean. if need to be more explicit just ask me :)

4
  • Is there any specific reason why you would want to do this without JQuery? It saves you from writing a lot of useless code. Commented Nov 9, 2017 at 11:36
  • 1
    @JesseSchokker best to learn the basics of native js before moving onto using libraries Commented Nov 9, 2017 at 11:43
  • Alright. I've answered your question, if you would mind accepting it. Commented Nov 9, 2017 at 11:43
  • yes I have a reason to use javascript. it is a project for an exam with JS only Commented Nov 9, 2017 at 11:48

2 Answers 2

1

Add id to you image element in html :

<img src = "anything" id= "myImage" >

then update it from you function in javascript :

function PlayPause() {
var imageElement = document.getElementById("myImage");

if (playing) {
    playing = false;
    Vianeos.pause();
    imageElement.src="img_1"
} else {
    playing = true;
    Vianeos.play();
    imageElement.src="img_2"
}   
};
Sign up to request clarification or add additional context in comments.

1 Comment

it is working thank you !
0

var imgEle = document.getElementById("imgtag"); imgEle.src="anything";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.