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 Connecting with the DOM Solution

Can I use Jquery to select the id and create the event listener?

Will this work?

$("#begin-game").click(function(){})

3 Answers

Elliott Rodriguez
Elliott Rodriguez
10,468 Points

I used plain JS like this to select the element.

const startButton = document.querySelector('#begin-game');

startButton.addEventListener().on(click, function () {
    game.startGame();

    this.style.display = 'none';
    document.getElementById('play-area').style.opacity = '1';
});
Ian Ostrom
seal-mask
.a{fill-rule:evenodd;}techdegree
Ian Ostrom
Full Stack JavaScript Techdegree Student 10,332 Points

David Aguirre here's a working jQuery solution.

$('#begin-game').click(function(){
    game.startGame();
    $(this).hide();
    $('#play-area').css('opacity', '1');
});

Note that using an arrow function would not work in this case. With an arrow function $(this) would be bound to the scope outside the arrow function. I learned this the hard way.