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 Object-Oriented JavaScript: Challenge Rendering the Game Rendering the Spaces, Board, and Tokens Solution

Shouldnt we set the attributes of the token HTML element before we append it?

drawHTMLToken() {
        const token = document.createElement('div')
        document.getElementById('game-board-underlay').appendChild(token)
        // shouldn't the following 3 lines of code go before the appendChild method?
        token.setAttribute('id', this.id)
        token.setAttribute('class', 'token')
        token.style.backgroundColor = this.owner.color
    }

Or would this mean that we can retrospectively change properties of a HTML element that we've already appended?

1 Answer

Hi, because this process within a function, it doesn't matter which one is doing first , eventually this function is going to create div element ,add all it's necessary properties and append to element id "game-board-underlay" anyway