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 trialDavid Aguirre
8,170 PointsCan I use Jquery to select the id and create the event listener?
Will this work?
$("#begin-game").click(function(){})
3 Answers
Piotr Manczak
Front End Web Development Techdegree Graduate 29,367 PointsAs far as I know you also have to use a link to jQuery library on the bottom of your HTML. Once its done jQuery will work.
Elliott Rodriguez
10,468 PointsI 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
Full Stack JavaScript Techdegree Student 10,332 PointsDavid 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.