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

214
Visualizações
Why is this.id not working in my switch...case?

The code should show the plot for the book cover you click on whilst changing the background to an alternative cover of the book, but it isn't doing anything. I have some backup code that works, but I liked this solution more.

My js code:

function mostraTrama(){
    try{
        switch(this.id){
            case "TramaVdR":
                nodoTramaVdR.setAttribute = ("class", "TramaScelta");
                nodoTramaPdL.setAttribute = ("class", "TramaNonScelta");
                nodoTramaG.setAttribute = ("class", "TramaNonScelta");
                document.body.style.backgroundImage = "url('../Images/way_of_kings_bg.jpg')";
                break
            case "TramaPdL":
                nodoTramaVdR.setAttribute = ("class", "TramaNonScelta");
                nodoTramaPdL.setAttribute = ("class", "TramaScelta");
                nodoTramaG.setAttribute = ("class", "TramaNonScelta");
                document.body.style.backgroundImage = "url('../Images/words_of_radiance_bg.jpg')";
                break
            case "TramaG":
                nodoTramaVdR.setAttribute = ("class", "TramaNonScelta");
                nodoTramaPdL.setAttribute = ("class", "TramaNonScelta");
                nodoTramaG.setAttribute = ("class", "TramaScelta");
                document.body.style.backgroundImage = "url('../Images/oathbringer_bg.jpg')";
                break
        }
    }
    catch(e){
        alert("mostraTrama " + e);
    }
}

function gestoreLoadRomanzi(){
    try {
        nodoTramaViaDeiRe = document.getElementById("TramaViaDeiRe");
        nodoTramaParoleDiLuce = document.getElementById("TramaParoleDiLuce");
        nodoTramaGiuramento = document.getElementById("TramaGiuramento");
        nodoTramaVdR = document.getElementById("TramaVdR");
        nodoTramaPdL = document.getElementById("TramaPdL");
        nodoTramaG = document.getElementById("TramaG");
        nodoTramaViaDeiRe.onclick = mostraTrama;
        nodoTramaParoleDiLuce.onclick = mostraTrama;
        nodoTramaGiuramento.onclick = mostraTrama;
    } catch ( e ) {
        alert("gestoreLoadRomanzi " + e);
    }
}

All three start off with class = "TramaNonScelta", which has display: none, and when clicked they should change to class = "TramaScelta", which has display: inline. The IDs all match to the ones they have in the HTML document.

My alternate functioning way is to have a separate function for each book instead of a single one for all of them.

EDIT: I also have a very similar code for another program that instead of using .setAttribute uses .innerHTML and works without any problems (but my professor doesn't want us to use .innerHTML in this project)

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