Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
How to show DOM changes every Iteration?

This code is supposed to shuffle between two images as many times as per user input. But the image swap done at last is only shown at the site. How to make the image change appear in website every single time its changed in the loop?

function runGif(){
    var count = document.getElementById("numb").value;
    var i=0;
    for(i=0; i<=count; i++){
        
            if(count%2==0){
                even();
            } else {
                odd();
            }
    
        console.log("LAP");
    
    }
}

function even(){
    document.getElementById("guy").src="2.png";
}

function odd(){
    document.getElementById("guy").src="1.png";
}
<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="style.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SHUFFLE BODY</title>
</head>
<body>
    <img src="1.png" id="guy">
    <input type="text" id="numb">
    <button onclick="runGif()">SUBMIT</button>
</body>
<script src="script.js">
</script>
</html>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to use timeout and delay function of js

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!