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

307
Views
How can i make something stay that way after clicking is done?

I have an image which is an arrow for sorting the list. When i click it has to change to other image which is downward of the same image. But it doesn't stay that way after clicking. . I need if else statement here because i will need the reverse list with new image after first click. It's not all of my Javascript. I tried to copy the parts which are related to my question. I hope it is an understandable example.

const sorting = document.querySelector('#sortingIcon');
let arr = [];
sorting.addEventListener('click', (event) => {

    if (sorting.src = "images/Group74.png") {
    sorting.src = "images/Group90.png";
    const items = document.getElementsByTagName('li');
    for (let i = 0; i < items.length; i++) {
        console.log(items[i])
        arr.push(items[i].firstChild.value);
    }
    arr.sort();
    for (let i = 0; i < items.length; i++) {
        items[i].firstChild.value = arr[i];
    }
}

})
<div class="box">
    <div id="yellow"></div>
    <h1>To-do list</h1>

    <img id="sortingIcon" src="images/Group74.png" alt="sorting">

    <div id="inputBox">
        <input class="input" type="text" name="input1">
        <img class="clear" src="images/Group77.png" alt="">
    </div>


    <button id="plus_button">
        <div id="flex">
            <div id="plus">+</div>
            <div id="enter">Добавить </div>
        </div>
    </button>
</div>

How can i make it stay that way?

about 4 years ago · Juan Pablo Isaza
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!