javascript - .JS Function will continue executing, with wrong values -


as can see simple application, code seems continue using first if statement though isn't correct/relevant anymore.

html

<div id="slideshow">    <img id="slide" src="images/slide01.jpg" width="600px" height="450px">      <button type="button" onclick="slideshowtimer()">click me!</button> </div> <!--closing slideshow--> 

js

function slideshowtimer() {     var img1 = "images/slide01.jpg";     var img2 = "images/slide02.jpg";     var img3 = "images/slide03.jpg";     var slide = document.getelementbyid('slide').src;      if (document.slide === document.img1) {         document.getelementbyid('slide').src = "images/slide02.jpg"; * * * //keeps executing once value has changed value of 'img2'***       } else if (document.slide === document.img2) {         document.getelementbyid('slide').src = "images/slide03.jpg";     } else if (document.slide === document.img3) {         document.getelementbyid('slide').src = "images/slide01.jpg";     } else {         alert("something went wrong");     } } 

it's because

 document.getelementbyid('slide').src 

returns absolute path.

edit:

function slideshowtimer() { var img1 = "images/slide01.jpg"; var img2 = "images/slide02.jpg"; var img3 = "images/slide03.jpg"; var slide = document.getelementbyid('slide');  if (slide.src.indexof(img1) >= 0) {    slide.src = "images/slide02.jpg";     alert('1'); } else if (slide.src.indexof(img2) >= 0) {     slide.src = "images/slide03.jpg";    alert('2'); } else if (slide.src.indexof(img3) >= 0) {    alert('3');     slide.src = "images/slide01.jpg"; } else {     alert("something went wrong"); } 

}


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -