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

Why create $pdfCheckbox?

Hi there, I was wondering why it is necessary to first create the const and then append it to the <div> instead of doing it at the same time?

$('#links').append('<label><input type='checkbox'> Allow PDF downloads</label>');

Also, why do we use '$' before the <label> tag, even though we are not selecting it from the HTML?

const $pdfCheckbox = $('<label><input type="checkbox> Allow PDF downloads</label>');

Thanks for your help!

3 Answers

victor cooper
victor cooper
6,436 Points

you wrote

$('#links').append$('<label><input type="checkbox"> Allow PDF downloads</label>');

remove the $ after the append and it will work fine, don't know if you will pass the task but you can use it this way

$('#links').append('<label><input type="checkbox"> Allow PDF downloads</label>');

true, the $ was in the way! thanks for looking at it!

victor cooper
victor cooper
6,436 Points

It's not necessary at all. what are you trying to achieve?

I'm referring to the task of adding the checkbox using jQuery. If I try this code:

$('#links').append$('<label><input type="checkbox"> Allow PDF downloads</label>');

without creating the variable first the checkbox doesn't show.