Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda