<script> function chg(id){ if (document.getElementById(id).src.indexOf("images/banner3.jpg")>0){ document.getElementById(id).src="images/big-logo.png" }else{ document.getElementById(id).src="images/banner3.jpg" } } </script> <img src="images/banner3.jpg" id="img_1" onClick="chg(this.id)"> 

Good day, with the help of this when when you click on the picture it changes to 2 and the second click back. I also need that after the first pressing, after n time, the picture is again changed to the first one.

  • and what's wrong with you? again "we ourselves in javacript 0 please help!" ? - zb '
  • Yes indeed in javacript 0, because now I am closely studying and doing a project on html + css, but for full implementation I need such a function. - lingvo
  • and what do you suggest ? write this function for you? $ 30 / hr - zb '
  • I do not ask to write this function for me, I ask you to help or at least give a couple of tips. No wonder I wrote this in "questions". - lingvo
  • setTimeout() - zb '22

2 answers 2

 function func() { $("#img_1").attr('src', 'img.png'); } setTimeout(func, 10000); 

    One solution is setTimeout. Executes the code (or function) specified in the first argument, asynchronously, with a delay in milliseconds ..

    An example is ONLY for understanding, NOT to use the code in a real project! (consider all recommendations for using the method, etc.)

     <script> function chg(id){ document.getElementById(id).src = 'images/big-logo.png'; setTimeout("document.getElementById('"+id+"').src = 'images/banner3.jpg'", 3000); } </script> <img src="images/banner3.jpg" id="img_1" onClick="chg(this.id)"> 

    typed for a long time :)

    • Thanks to both, the method works. - lingvo