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 trialSteve Fau
5,622 PointsShouldnt 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
}
1 Answer
Shumin Zhou
Full Stack JavaScript Techdegree Graduate 32,510 PointsHi, 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
Steve Fau
5,622 PointsSteve Fau
5,622 PointsOr would this mean that we can retrospectively change properties of a HTML element that we've already appended?