Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Cannot access offSetLeft property of DOM element

Here is the code

    get htmlToken() {
        return document.getElementById(this.id)
    }

    get offSetLeft(){
        return this.htmlToken.offSetLeft;
    }

Using console, I can see that the DOM object is being retrieved in the get htmlToken() getter method. However, when I try to access the offSetLeft property of it, it is coming back as undefined.

If I console.log the element returned by the htmlToken() getter method, it comes back as plain HTML, instead of the full object, which is what I believe maybe the issue.

If console.dir() the DOM object, I can see the offSetLeft property does exist on the DOM object, as well has having an int value of 0.

1 Answer

I figured out what the problem was. The code was not working due to a casing issue I declared the getter method as offsetLeft, but was trying to access is it as offSetLeft.

This is resolved