Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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,408 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,408 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.