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

217
Views
Compruebe si un elemento en LocalStorage es nulo y no cambia los fondos

Hice una página de configuraciones que cuando presiono un botón cambia el fondo, a un color o a una imagen, creé el img localStorages y el color, mi problema es que cuando no son nulos al mismo tiempo, en lugar del el fondo que va por la imagen sirve para hacer el fondo con el "color", el código que estoy intentando es este:

 if (localStorage.getItem("Color") === null) { //if Color is null if (localStorage.getItem("img") === null) {// And Image too document.body.style.backgroundImage = "url('css/Images/Instruments/pexels-pixabay-459797.jpg')"; // a image appear in the background } else { // else if Color is null but img isint document.body.style.backgroundImage = localStorage.getItem("img"); //load the image in the background } // THIS IS My problem: i dont know how to check if both arent null if(localStorage.getItem("Color") !== 'null' localStorage.getItem("img") !== 'null'){ //If Both arent null document.body.style.backgroundImage = localStorage.getItem("img"); // load the Image not the background } }};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

puedes usar el operador lógico &&, así:

 if (!localStorage.getItem('color') { if (!localStorage.getItem('img') { document.body.style.backgroundImage = 'url("your image url")'; } else { document.body.style.backgroundImage = localStorage.getItem('img'); } if (localStorage.getItem('color') && localStorage.getItem('img') { document.body.style.backgroundImage = localStorage.getItem('img'); } }
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!