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

178
Views
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 answers
Answer question

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 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!