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

176
Vistas
I can't make this.getAttribute working, the browser says it's not a function

The browser says that this.getAttribute is not a function. I've seen a similar post on Stack, the OP was told to send this to the function, but it doesn't work for me. Here's the snippet:

function reveal()
{
    this.src = "img/" + this.getAttribute("data-value") + ".png";
}

function display_cards(cards, n)
{
    for (i = 0; i < cards.length; i++)
    {
        if (i % n == 0)
        {
            document.getElementById("container").innerHTML += '<br/>';
        }
        document.getElementById("container").innerHTML += '<img src="img/back.png" class="card" onclick="reveal(this)" data-value="'+cards[i]+'"/>';
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Get this in function as an incoming parameter: function reveal(img), for example.

const cards = ["linear-flat-wedding-monograms_52683-64319",
            "flat-car-poster-with-photo-horizontal_52683-64510",
            "gradient-grainy-gradient-shapes_23-2148975080"];

display_cards(cards,3)



function reveal(img)
{
    img.src = "https://image.freepik.com/free-vector/" + img.getAttribute("data-value") + ".jpg";
}

function display_cards(cards, n)
{
    for (i = 0; i < cards.length; i++)
    {
        if (i % n == 0)
        {
            document.getElementById("container").innerHTML += '<br/>';
        }
        document.getElementById("container").innerHTML += '<img src="https://image.freepik.com/free-vector/gradient-grainy-gradient-shape-set_23-2148971570.jpg" class="card" onclick="reveal(this)" data-value="'+cards[i]+'"/>';
    }
}
<div id="container"></div>

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