Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
Move color of an HTML element to another page

Good evening, i was working on a part of what i hope will be my future website and i wanted to add a "photograpy" section to it, and here comes the problem. since the title in the main page constatly changes color, i'd like to grab its current color to transfer it to the title of the other page to play an animation later on. the problem is that when i press the related button, i am taken to the photograpy page, but the title remains black. i've tried seraching for help on google but i haven't been able to find much. here is the JS

if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", function() {
        loaded();
    });
} else if (document.attachEvent) {
    document.attachEvent("onreadystatechange", function() {
        loaded();
    });
}

function loaded() {
    document.getElementById("PHtitle").style.color === titlecolor;
}

function script() {
    const titlecolor = document.getElementById("title").style.color;
};

document.getElementById('photograpy').onclick = function () {
    script();
};
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The snippets don't allow for localStorage, so here is just the javascript.

First, I let the variables outside of a function. The titleColor function checks to see if titleColor was saved in localStorage, if not the default color is black.

Then I set the color of the phtitle to the contents of titleColor variable.

In the script function, I set the localStorage variable to the getComputedStyle color of the title.

Then last I use an event listener on the button to run the script for saving the color.

LocalStorage is a way to store data in the user's browser until they close their browser/clear their data etc.. Which will allow it to be usable on different pages then where it was saved.

    let titleColor = localStorage.getItem("titleColor") || "#000000";
    let PHtitle = document.querySelector("#PHtitle");
    let title = document.querySelector("#title");
    let btn = document.querySelector("#photography");
    
if(PHtitle){
    PHtitle.style.color = titleColor;
}
    
    function script() {
      localStorage.setItem("titleColor", getComputedStyle(title).color)
    }
    
if(btn && title){
    btn.addEventListener("click", function() {
      script();
    })
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda