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

209
Views
How do i switch the button icon from nightmode to day mode?

In the below code I have linked some js/jQuery to elements in my html which should be self explanatory. I have console logged each if else statement to see what the issue is and it seems to be stuck on the first if statement.

function toggleDisplay() {
var icon = document.getElementById("togglebutton");
var night_icon = 'assets/Feed_Toggle_Night.png'
var day_icon = 'assets/Feed_Toggle_Day.png'
$("displaytog").on("click", () => {
    if (icon.src == night_icon) {
        icon.src = day_icon;
        console.log("success1");
    }else {
        icon.src = night_icon;
        console.log("success2");
    }
})
}
toggleDisplay();
<displaytog>
  <img src="assets/Feed_Toggle_Night.png" id="togglebutton"/>
</displaytog>

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

0

You are assigning icon.src to night_icon by accident. change your condition to check if they include any of your paths. the reason you need to use includes is because the src is a full path while your conditions are using relative paths. The src looks like this - "https://fiddle.jshell.net/_display/assets/Feed_Toggle_Day.png"

 if (icon.src.includes(night_icon))
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!