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

144
Views
Why can't I point to properties of an object from a method of the same object with 'this' keyword on click events

When i click on the button, the product name disappears, and the numberical, boolean values disappear.

const product =
{
    name:'Gummy Bears',
    inStock:true,
    price:1.99,
    flavors:["grapes","apple","cherry"],

    printProduct: function () {
        const self = this;
        console.log(self)
        document.querySelector('.name').innerHTML = self.name;
        document.querySelector('.instock').innerHTML = this.inStock;
        document.querySelector('.price').innerHTML = this.price;
        document.querySelector('.flavors').innerHTML = this.flavors[0];
    }

}

// product.printProduct()

 document.getElementById('button').addEventListener('click', product.printProduct)

enter image description here

I tried everything and it does not seem to work.

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